我已经定义了 2 条自定义路线。一个 forthreads/:id/:name
和另一个 forthreads/tags/:tagName
但是第二个与第一个冲突,因为如果我启用两者,那么第一个会中断并将:id
字面上视为一个动作,不遵守\d+
要求(我也尝试使用纯正则表达式路由,见底部)。
动作“1”不存在并且没有被困在 __call()
我尝试重新安排路线的顺序,但如果我这样做,则threads/tags/:tagName
不会正确捕获 tagName。
我也尝试禁用默认路由,但之后路由仍然无法正常工作。
这是我的路由初始化函数:
protected function _initRoutes() {
$fc = Zend_Controller_Front::getInstance();
$router = $fc->getRouter();
$router->addRoute(
'threads',
new Zend_Controller_Router_Route('threads/:id/:name',
array(
'controller' => 'threads',
'action' => 'thread',
),
array(
'id' => '\d+'
)
)
);
$router->addRoute(
'threads',
new Zend_Controller_Router_Route('threads/tags/:tagName',
array(
'controller' => 'threads',
'action' => 'tags',
),
array(
'tagName' => '[a-zA-Z]+'
)
)
);
}
我也尝试使用纯正则表达式路由但不成功,很可能是因为我做错了:
$router->addRoute(
'threads',
new Zend_Controller_Router_Route_Regex(
'threads/(\d+)/([a-zA-Z]+)',
array(
'controller' => 'threads',
'action' => 'thread',
),
array(
1 => 'tagName',
2 => 'name'
)
)
);