1
我已经定义了2个自定义路由。一个用于threads/:id/:name
,另一个用于threads/tags/:tagName
但是第二个与第一个冲突,因为如果我启用两个然后第一个休息并将:id
字面上看作是一个动作,而不是遵守\d+
要求(我也尝试使用纯正则表达式路由,请参见底部) 。Zend路由冲突
行动“1”不存在,并没有 被困在__call()
我试图路由的重新排列顺序,但如果我这样做,那么threads/tags/: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'
)
)
);