Studyon Minte9.com
ZF 1.0




View



When writing views, some time sooner or later, you?re going to be creating links to your own pages. 
Because you don?t want to end up writing relative URLs (they will not work, because the browser will add them to
 the current path), you need to have some kind of a base URL.

The URL view helper will create URLs for you, based on your custom routes, and using the base URL set in your 
front controller.


Application/config/routes.ini
------------------------------

...

;ARTICLE
routes.article.type = "Zend_Controller_Router_Route_Regex"
routes.article.route = "([a-z_/-]+)/([a-z0-9-_.]+)_(d+)"
routes.article.defaults.module = "default"
routes.article.defaults.controller = "frontend"
routes.article.defaults.action = "article"
routes.article.map.1 =  category
routes.article.map.2 =  slug
routes.article.map.3 =  article_id
routes.article.reverse =  "%s/%s_%d"

; chain
routes.service_root.chains.list_dealer_details.type = "Zend_Controller_Router_Route_Regex"
routes.service_root.chains.list_dealer_details.route = "([0-9a-z-]+)_([0-9]+)"
routes.service_root.chains.list_dealer_details.defaults.module = "dealers"
routes.service_root.chains.list_dealer_details.defaults.controller = "frontend"
routes.service_root.chains.list_dealer_details.defaults.action = "details"
routes.service_root.chains.list_dealer_details.defaults.type = 1
routes.service_root.chains.list_dealer_details.map.1 = "slug_dealer"
routes.service_root.chains.list_dealer_details.map.2 = "id_dealer"
routes.service_root.chains.list_dealer_details.reverse = "%s_%d"



Application/modules/default/views/scripts/frontend/test.phtml
-------------------------------------------------------------

<a href='<?php echo $this->url(array(
	'category' => 'news',
	'slug' => 'some_article',
	'article_id' => 55,
	), 'article'); ?>'>TEST</a>

	<!-- TEST LINK IS: http://zfsite/news/some_article_55 -->

<a href='<?php echo $this->url(array(
      'module' => 'article',
      'controller' => 'frontend',
      'action' => 'show',
      'id' => 1,
      'slug' => 'union',
      'catgs' => 'mysql/queries',
      ), 'article', true, false); ?>'>TEST2</a>

      <!-- TEST LINK IS: http://zfsite/msyql/queries/select/union_55 -->
      <!-- false: without encode / -->

<a href='<?php echo $this->url(array(), 'service_root-chains.list_dealer_details'); ?>'>Test Chain</a>

// url(array $urlOptions = array(), $name = null, $reset = false, $encode = true)

     * @param  array $urlOptions Options passed to the assemble method of the Route object.
     * @param  mixed $name The name of a Route to use. If null it will use the current Route
     * @param  bool $reset Whether or not to reset the route defaults with those provided
     * @return string Url for the link href attribute.
	
	http://naneau.nl/2007/07/08/use-the-url-view-helper-please/
	<a href="/my_app/user/edit/id/123/">click me!</a>

	While they will function perfectly, there?s two problems, both related to manageability of your website. 
	First is that if your base URL changes (the ?/my_app/?), you will have to edit all of your views. 
	Second is that if you use custom routes you may end up with outdated routes, or even worse, erroneous 
routes in your views.


// to reset the route user 'default' route (will not work with null)
	
	<a href="<?php echo $this->url(array(
		 'module' => 'user',
		 'controller' => 'useraccount',
		 'action' => 'logout',
	), 'default', true); ?>">Logout</a>


http://blog.ericlamb.net/2010/04/zend-framework-url-view-helper/
http://framework.zend.com/issues/browse/ZF-5777