Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to specify a dynamic default for a key in a router, Zend Framework
    primarykey
    data
    text
    <p>This question is linked to <a href="https://stackoverflow.com/questions/916143/adding-a-route-to-the-a-router-in-zend-framework">this one</a> </p> <p>How can I set the default of the category part to be the category value in the request url?</p> <pre><code>$Router=$this-&gt;_front-&gt;getRouter(); $CategoryRoute = new Zend_Controller_Router_Route('category/:category/:controller/:action/*', array( 'controller' =&gt; 'index', 'action' =&gt; 'index', 'category' =&gt; 'aaa' )); $Router-&gt;addRoute('category', $CategoryRoute); </code></pre> <p>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.</p> <p>Example of what I mean:<br> If I surf to the site with url <a href="http://baseurl/category/mycat/index" rel="nofollow noreferrer">http://baseurl/category/mycat/index</a><br> I will be routed to controller=index, action=index, category=mycat.<br> But, in all my view files, where I use the Zend_View::url() helper, the links will point to:<br> <a href="http://baseurl/category/aaa/somthing/somthing" rel="nofollow noreferrer">http://baseurl/category/aaa/somthing/somthing</a> (Using the exact route from above)<br> While I actually need them to point to:<br> <a href="http://baseurl/category/mycat/somthing/somthing" rel="nofollow noreferrer">http://baseurl/category/mycat/somthing/somthing</a> </p> <p>This happens because the default value for category is written as a constant in the route, and not taken, somehow, from the current URL.<br> I currently solve this by extracting by myself the category from the URL and making it the default. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload