Zend naviagtion does not work due to zend route

EDIT :: the problem was caused due to the zend route, please check for updates.

I am using an xml file for navigation.

EDIT :: following code from layout.phtml

$config = new Zend_Config_Xml(APPLICATION_PATH.'/configs/adminnav.xml', 'nav'); $container = new Zend_Navigation($config); $this->navigation()->setContainer($container); echo $this->navigation(); 

when I am on my edit page, everyone does not have a menu link. everyone gets / admin / controller / edit / everywhere in the menu item. any idea?

my editing action takes id, if id is not specified, it generates and throws an error. however the add and list method works fine

UPDATE ::

 <?xml version="1.0"?> <config> <nav> <home> <label>home</label> <uri>#</uri> <pages> <home> <label>home</label> <module>admin</module> <controller>home</controller> <action>index</action> </home> <help> <label>help</label> <module>admin</module> <controller>home</controller> <action>help</action> </help> </pages> </home> <page> <label>pages</label> <uri>#</uri> <pages> <static> <label>static pages</label> <module>admin</module> <controller>page</controller> <action>index</action> </static> <editpage> <label>static pages</label> <module>admin</module> <controller>page</controller> <action>edit</action> </editpage> </pages> </page> <destination> <label>destinations</label> <uri>#</uri> <pages> <list> <label>list all</label> <module>admin</module> <controller>destination</controller> <action>index</action> </list> <featured> <label>featured</label> <module>admin</module> <controller>destination</controller> <action>featured</action> </featured> <add> <label>add destination</label> <module>admin</module> <controller>destination</controller> <action>add</action> </add> <editdest> <label>edit destination</label> <module>admin</module> <controller>destination</controller> <action>edit</action> </editdest> </pages> </destination> <tours> <label>tours</label> <uri>#</uri> <pages> <list> <label>list tours</label> <module>admin</module> <controller>tour</controller> <action>index</action> </list> <featured> <label>featured tours</label> <module>admin</module> <controller>tour</controller> <action>featured</action> </featured> <add> <label>add tours</label> <module>admin</module> <controller>tour</controller> <action>add</action> </add> <edittour> <label>edit tours</label> <module>admin</module> <controller>tour</controller> <action>add</action> </edittour> </pages> </tours> <hotels> <label>hotels and resort</label> <uri>#</uri> <pages> <list> <label>list hotel</label> <module>admin</module> <controller>hotel</controller> <action>index</action> </list> <add> <label>add hotel</label> <module>admin</module> <controller>hotel</controller> <action>add</action> </add> <edithotel> <label>add hotel</label> <module>admin</module> <controller>hotel</controller> <action>add</action> </edithotel> </pages> </hotels> <message> <label>message</label> <uri>#</uri> <pages> <all> <label>all message</label> <module>admin</module> <controller>message</controller> <action>index</action> </all> <contactus> <label>contact</label> <module>admin</module> <controller>message</controller> <action>contact</action> </contactus> <inquiry> <label>inquiry</label> <module>admin</module> <controller>message</controller> <action>inquiry</action> </inquiry> <reservation> <label>reservation</label> <module>admin</module> <controller>message</controller> <action>reservation</action> </reservation> </pages> </message> <advertisement> <label>advertisement</label> <uri>#</uri> <pages> <list> <label>list ads</label> <module>admin</module> <controller>advertisement</controller> <action>index</action> </list> <add> <label>add ads</label> <module>admin</module> <controller>advertisement</controller> <action>add</action> </add> <editad> <label>edit ads</label> <module>admin</module> <controller>advertisement</controller> <action>edit</action> </editad> </pages> </advertisement> <setting> <label>settings</label> <uri>#</uri> <pages> <view> <label>view</label> <module>admin</module> <controller>setting</controller> <action>view</action> </view> <account> <label>account setting</label> <module>admin</module> <controller>setting</controller> <action>account</action> </account> <site> <label>site setting</label> <module>admin</module> <controller>setting</controller> <action>site</action> </site> </pages> </setting> </nav> </config> 

UPDATE :: route for edit action on bootstrap.php

  $frontcontroller = Zend_Controller_Front::getInstance(); $router = $frontcontroller->getRouter('router'); //add route for edit page so that pageid is not displayed in the url $router->addRoute( 'edit-page', new Zend_Controller_Router_Route('admin/page/edit/:pageid', array( 'module' => 'admin', 'controller' => 'page', 'action' => 'edit', 'pageid' => 'pageid' )) ); 

UPDATE :: Phil

 <editdest> <label>edit destination</label> <module>admin</module> <controller>destination</controller> <action>edit</action> <route>12</route> </editdest> 

Error for this ::

 Fatal error: Zend_Controller_Router_Exception: Route 12 is not defined in /usr/share/php/libzend-framework-php/Zend/View/Helper/Navigation/HelperAbstract.php on line 522 
+4
source share
2 answers

If there are any static routes, you need to specify the name of the route on all navigation pages. This is because the navigation helper uses the Url view helper to create links.

If the route name is missing, it uses the current route.

If the current route is static, it will only allow one URL, no matter what parameters throw it.

+3
source

You should use the route that you defined in $router->addRoute .

It should be:

 $router->addRoute( 'edit-page', new Zend_Controller_Router_Route('admin/page/edit/:pageid', array( 'module' => 'admin', 'controller' => 'destination', 'action' => 'edit', 'pageid' => 'pageid' )) ); <editdest> <label>edit destination</label> <module>admin</module> <controller>destination</controller> <action>edit</action> <route>edit-page</route> <params> <pageid>12</pageid> </params> </editdest> 

If you need different editing links on each page, you need to update the parameters in the navigation container dynamically, that is:

 // (pseudocode, not tested) $this->navigation()->getContainer()->findOneByLabel('edit destination')->params->pageid = 12 
+1
source

Source: https://habr.com/ru/post/1337327/


All Articles