I have 2 similar routes set up for my ZF application, one of which works and one of which doesn't. This one, which displays an item from the database for the user to view, works perfectly:
Route in my bootstrap:
//Static item profile
$route = new Zend_Controller_Router_Route('item/:item_id',
array('controller'=> 'item',
'action'=> 'index'));
$router->addRoute('item', $route);
And where I get the item id in the item controller's index action:
$id = $this->getRequest()->getParam('item_id');
I have this one set up in my back end to allow admins to edit item data:
//Management back end
$route = new Zend_Controller_Router_Route('manage/edititem/:item_id',
array('controller'=> 'manage',
'action'=> 'edititem'));
$router->addRoute('manage', $route);
And this is where I get the id in the manage controller's edititem action:
$item_id = $this->getRequest()->getParam('item_id');
For some reason the item_id in this one always comes up null if I navigate to /manage/edititem/:item_id, though it works perfectly fine if I go to /manage/edititem/item_id/:item_id. Why would the route not work if I try to use the custom route? It's not getting caught by an earlier route because it's still executing the code inside the edititem action, I'm not missing any semicolons above it, and I copied and pasted it over, so I doubt it is a typo. What could be wrong with my route?
$this->getFrontController()->getRouter()->getCurrentRouteName()
in your controller, which of your routes are matched. Also check that your routes added in the right order (most generic at first). – ByteNudger$this->getFrontController()->getRouter()->getRoutes()
(you should usearray_keys()
to only print the route names). If the route isn't there you should check your code in theBootstrap.php
, because somehow you maybe overwrite a variable or didn't add the route. You should print the names in yourBootstrap.php
and controller to see if something changing your routes between these two. – ByteNudger