我正在使用 Zend Framework,并尝试设置一些自定义路由。
这些在调度期间似乎工作正常,但反向匹配根本不起作用。
这些是我设置的路线。
$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'
)
));
如果我现在去http://example.com/categories http://example.com/categories,执行正确的控制器和操作(category.index)。如果我去http://example.com/categories/5 http://example.com/categories/5,我收到以下错误:
Fatal error: Uncaught exception 'Zend_Controller_Router_Exception' with
message 'category is not specified'
向 :category 添加默认值可以解决此问题(欢迎提出建议)。
但这不是主要问题。
每当我的应用程序执行时$this->url(...)
,返回值始终是当前 URL。很快http://example.com/categories http://example.com/categories,如果我跑
echo $this->url(
array('controller' => 'category', 'action' => 'modify', 'category' => 5)
);
返回值为http://example.com/categories
。我完全被难住了..
即使我尝试绕过默认路由器并执行以下操作,问题仍然存在
$router->removeDefaultRoutes();
$router->addRoute('default', new Zend_Controller_Router_Route(
'*',
array('controller' => 'index', 'action' => 'index')
));
有没有对 Zend 路由有更多经验的人想尝试一下这个?
干杯,
乔恩