Zend_Controller_Router_Exception: "xyz" not specified

I have a problem in my current Zend Framework application.

In my Bootstrap, I register these routes:

protected function _initRouter() { $this->bootstrap("FrontController"); $frontController = $this->getResource("FrontController"); $route = new Zend_Controller_Router_Route( ":module/:id", array( "controller" => "index", "action" => "index" ), array("id" => "\d+") ); $frontController->getRouter()->addRoute('shortcutOne', $route); $route = new Zend_Controller_Router_Route( ":module/:controller/:id", array("action" => "index"), array("id" => "\d+") ); $frontController->getRouter()->addRoute('shortcutTwo', $route); $route = new Zend_Controller_Router_Route( ":module/:controller/:action/:id", null, array("id" => "\d+", "action" => "\w+") ); $frontController->getRouter()->addRoute('shortcutThree', $route); } 

Now I have added Zend_Navigation to my project. I have several modules that register navigation elements in the module bootstrap:

 <?php class Contact_Bootstrap extends Zend_Application_Module_Bootstrap { protected function _initNavigation() { $layout = $this->getApplication()->getResource("layout"); $view = $layout->getView(); $config = new Zend_Config_Xml(dirname(__FILE__)."/config/navigation.xml", "nav"); $view->navigation()->addPage($config); } } 

When I open the application in my browser, everything works fine. This means that I see the navigation and click on its links to view the specified page. But when I click on the page using the route: module /: action /: id, the Navigation Helper throws a Zend_Controller_Router_Route exception:

Fatal error: Zend_Controller_Router_Exception: id not specified in C: \ Entwicklung \ kt \ trunk \ src \ library \ Zend \ View \ Helper \ Navigation \ HelperAbstract.php on line 519

Have any of you experienced this error too? It would be great if you could help me or give me advice. Also, if you need more information about my setup, etc., just tell me.

Thanks!

+4
source share
6 answers

I found a solution myself.

This problem arose because of the not very useful behavior of the Zend_Navigation elements. In the getHref () method, they use the URL helper. This helper creates the URL that the navigation entry should reference, taking the arguments specified for the navigation element (module, controller, action, etc.).

Now the problem is that if you created your own route in your boot block just like me, for example

 ":module/:controller/:id" 

You have encountered a problem that when using this route, the URL helper uses this route to create a link to record navigation. However, I did not pass the optional id parameter, so I got an exception.

Thus, one of the solutions is to pass an additional parameter for each "route" Zend_Navigation_Page_Mvc, which is set to "default".

Another solution that I have not tried yet is to make the new user route simply re-qualify itself as the default route, for example:

 ":module/:controller/:action/id/$id" 

But I do not know if you have the opportunity with the Zend Framework to do this.

+6
source
 $route = new Zend_Controller_Router_Route( "info/:id", array( "controller" => "index", "action" => "index" ), array("id" => "\d+") ); 

changed to

 $route = new Zend_Controller_Router_Route( "info/:id", array( "controller" => "index", "action" => "index", "id" => "default" ) ); 

worked for me, but probably this is not the best way to go

+4
source

I ran into the same problem and here is the solution that worked for me: I added a route parameter to all my links in the navigation.xml file below

  <?xml version="1.0" encoding="UTF-8"?> <navigation> <mainmenu> <home> <label>topmenu:homepage</label> ===> <route>default</route> <=== <module>default</module> <controller>index</controller> <action>index</action> </home> </mainmenu> </navigation> 
+3
source

In this route ": module /: controller /: id" you just need to define the default value for: id

Example:

 <content type="Zend_Controller_Router_Route"> <route>content/:engine</route> <defaults module="content" controller="engine" action="index" engine="" /> </content> 

Sorry for my English:)

Sincerely.

+2
source

I just ran into a problem similar to yours, but found another workaround for it. I will talk about it here for information only.

Like you, my problem was that my navigation was built using the last route used. This meant that if one of my user routes was used, I would get a stack of exceptions complaining about some user parameters for this given route that are not defined.

Most of the user-defined parameters for my routes default to zero in the route definition. I found that instead of changing the default value to "", the exception will actually disappear. I could not understand this, so I started to walk a little and stumbled upon your post, which led me on the right path - I think.

My navigation elements are stored in a database, so I can generate all my Zend_Navigation_Page elements on request and pass the container to my view helpers (I am serializing my container object to make it cacheable, but this is not relevant right now). I really did not find that changing the default params for '' showed that this is a “good” way to do this, so I hinted at your post. I tried to change all the page elements stored in my database to use the named 'default' route, if they are clearly not intended to use a custom route and have parameters defined for it. Explicitly defining my waypoints for using the default route seemed to help too, and for me it seems to be a cleaner solution.

Thanks for the hint about what caused this error - except, I really didn't know where to start:

+2
source

I see two solutions here:

  • You can set the default value for route parameters in _initRouter (), but it may not be what you want (for example, in this case this route can be used when you do not want it)

  • You can specify the route parameters in the navigation.xml file (params property). If you do not want to install them fixed, you will need to write PHP code to generate navigation xml.

0
source

All Articles