views:

201

answers:

2

This question is linked to this one

How can I set the default of the category part to be the category value in the request url?

$Router=$this->_front->getRouter();
$CategoryRoute = new Zend_Controller_Router_Route('category/:category/:controller/:action/*',
           array(
                 'controller' => 'index',
                 'action'     => 'index',
                 'category'   => 'aaa'
           ));
$Router->addRoute('category', $CategoryRoute);

In other words, I need the value [aaa] to be the value of category in the time I am building this route. There will always be a value for [category] as otherwise it will use the default route.

Example of what I mean:
If I surf to the site with url http://baseurl/category/mycat/index
I will be routed to controller=index, action=index, category=mycat.
But, in all my view files, where I use the Zend_View::url() helper, the links will point to:
http://baseurl/category/aaa/somthing/somthing (Using the exact route from above)
While I actually need them to point to:
http://baseurl/category/mycat/somthing/somthing

This happens because the default value for category is written as a constant in the route, and not taken, somehow, from the current URL.
I currently solve this by extracting by myself the category from the URL and making it the default.

A: 

Is there a question in your post? :)

IF I got you right - yousetup your default category and it will be used if you call

$this->url(array(),'category');

But when you use

$this->url(array('category'=>'my-category'),'category');

it will return category/my-category/index/idnex instead of category/aaa/index/index

Tomáš Fejfar
No, I will always use url(array(),null,true); The router used will be decided by the URI. This works fine. The problem is, the url() helper does not take the value of category from the URL, but rather expects me to enter it manually in the helper url(array('category'=>'somevalue')); This I am trying to avoid. I can avoid this by entering a default value to [category] when I build the new route. Problem is, it is a static value, where it has to be the value in URL. I solve this temporarily by extracting myself the value of [category] and making it the default.
Itay Moav
This should not happen. The last param of url() toggles "route reset" - if it's fast or ommited then the route should be filled from current URL. Try dumping the route used. (sth like $frontContr->getRouter()->...)
Tomáš Fejfar
*fast = false ;)
Tomáš Fejfar
A: 

If you use

$this->url(array(), 'category');

it should work.

But keep in mind : as long as you stick to the default values, you will always get a simple /category link, but when using different parameters it should return the correctly adapted URL based on the current URI.

ie. if URI is /category/aaa/index/index then $this->url(array(), 'category'); will return /category, if URI is /category/xxx/index/index then $this->url(array(), 'category'); will return /category/xxx, if URI is /category/xxx/index/process then $this->url(array(), 'category'); will return /category/xxx/index/process, etc.

wimvds