Note that there are some explanatory texts on larger screens.

plurals
  1. POZend Controller Router : Define variables to point to a different action in one controller
    primarykey
    data
    text
    <p>I'm just new with Zend and I have a little trouble with Zend Routers. I've searched about it, but nothing found...</p> <p>I want to be able to define a router for each defined variable at uri level to point to a different action in one controller.</p> <p>I'm working with lang and modules so I defined at bootstrap application the next initRoutes function:</p> <pre><code>protected function _initRoutes() { $front = Zend_Controller_Front::getInstance(); $router = $front-&gt;getRouter(); $defaultRoute = new Zend_Controller_Router_Route( ':lang/:module/:controller/:action', array( 'lang' =&gt; 'es', 'module' =&gt; 'default', 'controller' =&gt; 'index', 'action' =&gt; 'index' ), array( 'lang' =&gt; '^(en|es)$', 'module' =&gt; '^(default|admin)$' ) ); $router-&gt;addRoute('defaultRoute', $defaultRoute); return $router; } </code></pre> <p>I want to be able to access forum sections and forum topics by their defined action.</p> <p>Something like : </p> <ul> <li><p>mydomain/forum -> forum/index</p></li> <li><p>mydomain/forum/section -> forum/sectionAction</p></li> <li><p>mydomain/forum/section/topic -> forum/topicAction</p></li> </ul> <p>and also with the lang and module defined at uri level like :</p> <ul> <li><p>mydomain/lang/module/forum</p></li> <li><p>mydomain/lang/module/forum/section</p></li> <li><p>mydomain/lang/module/forum/section/topic</p></li> </ul> <p>So I have this :</p> <pre><code>class ForumController extends Zend_Controller_Action { public function indexAction() { } public function sectionAction() { } public function topicAction() { } </code></pre> <p>Then I created the next routes inside the Default_Bootstrap :</p> <pre><code>$forumRoutes = new Zend_Controller_Router_Route( ':lang/:module/forum', array( 'lang' =&gt; 'es', 'module' =&gt; 'default', 'controller' =&gt; 'forum', 'action' =&gt; 'index' ) ); $sectionRoutes = new Zend_Controller_Router_Route( ':lang/:module/forum/:section', array( 'lang' =&gt; 'es', 'module' =&gt; 'default', 'controller' =&gt; 'forum', 'action' =&gt; 'section', 'section' =&gt; '' ) ); $topic = new Zend_Controller_Router_Route( ':lang/:module/forum/:section/:topic', array( 'lang' =&gt; 'es', 'module' =&gt; 'default', 'controller' =&gt; 'forum', 'action' =&gt; 'topic', 'section' =&gt; '', 'topic' =&gt; '' ) ); $router-&gt;addRoute('forumTopics', $topic); $router-&gt;addRoute('forumSections', $section); $router-&gt;addRoute('forum', $forumRoutes); </code></pre> <p>Now, this only works if I define the lang and module at uri level, but doesn't work if I defined like => mydomain/forum/section | section/topic. This also brings me another problem with my navigation->menu. If I define "forum" as a static variable at router definition, when I hover over at any label defined at navigatoin.xml, the uri level have the same value for every one of them.</p> <p>I've tried to make a chain like this: </p> <pre><code> $forumRoutes = new Zend_Controller_Router_Route( ':lang/:module/forum', array( 'lang' =&gt; 'es', 'module' =&gt; 'default', 'controller' =&gt; 'forum', 'action' =&gt; 'index' ) ); $section = new Zend_Controller_Router_Route( ':section', array( 'action' =&gt; 'section', 'section' =&gt; '' ) ) $topic = new Zend_Controller_Router_Route( ':topic', array( 'action' =&gt; 'topic', 'topic' =&gt; '' ) ) $chainedRoute = new Zend_Controller_Router_Route_Chain(); $chainedRoute-&gt;chain($topic) -&gt;chain($section) -&gt;chain($forumRoutes); $router-&gt;addRoute($chainedRoute); </code></pre> <p>But this doesn't work as I expected.</p> <p>Any help would be appreciated, thanks.</p>
    singulars
    1. This table or related slice is empty.
    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.
    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