I'm using Zend Framework, and am trying to set up some custom routes. These seem to be working fine during dispatch, but the reverse matching isn't working at all.
These are the routes I've set up.
$router->addRoute('category', new Zend_Controller_Router_Route(
'categories/:category',
array(
'controller' => 'category',
'action' => 'modify',
)
));
$router->addRoute('categories', new Zend_Controller_Router_Route_Static(
'categories',
array(
'controller' => 'category',
'action' => 'index'
)
));
If I now go to http://example.com/categories, the correct controller and action are executed (category.index). If I go to http://example.com/categories/5, I get the following error:
Fatal error: Uncaught exception 'Zend_Controller_Router_Exception' with
message 'category is not specified'
Adding a default value to :category fixes this problem for reason (suggestions welcome). That is not the major problem though.
Whenever my application executes $this->url(...)
, the returned value is always the current URL. So, on http://example.com/categories, if I run
echo $this->url(
array('controller' => 'category', 'action' => 'modify', 'category' => 5)
);
The returned value is http://example.com/categories
. I am completely stumped..
The problem persists even if I try to bypass the default router and do
$router->removeDefaultRoutes();
$router->addRoute('default', new Zend_Controller_Router_Route(
'*',
array('controller' => 'index', 'action' => 'index')
));
Does anyone with a bit more experience with Zend routing want to have a crack at this?
Cheers, Jon