Zend Route:如果链接以 /something 开头,则忽略其他规则
我有两个模块应该覆盖其他网址,基本上
/management/category/edit/id/1 (编辑类别页面)
/management/category/index (管理模块中类别的索引页面)
/management/category (管理模块中类别的索引页面)管理模块中的类别)
/women-like-men/category (URL 路由自 /default/category/view/id/women-like-men)
上述规则是:
$router->addRoute('view-category', new Zend_Controller_Router_Route(':id/category/:page', array('module' => 'default', 'controller' => 'category', 'action' => 'view', 'page' => null)));
$router->addRoute('management/category', new Zend_Controller_Router_Route('management/category/', array('module' => 'management', 'controller' => 'category', 'action' => 'index')));
有很多类似的页面,“冲突” “(画廊、电影、用户)等。
我真正想要的是一条规则,规定 /management/* 路由到模块管理/控制器/操作,并忽略下面的规则,任何带有 /management 的规则。无论如何,用户/画廊/电影/类别被称为管理的可能性很低。
是否可以?
编辑,我做了这个:
$router->addRoute('administration', new Zend_Controller_Router_Route_Regex('management/?(.*)/?(.*)', array('module' => 'management'), array(1 => 'controller', 2 => 'action')));
/management/category 工作正常,但是之后的任何内容都会导致 404
I have two modules that should over ride other urls, basically
/management/category/edit/id/1 (Edit Category Page)
/management/category/index (Index Page Of Category in Management Module)
/management/category (Index Page Of Category in Management Module)
/women-like-men/category (URL Routed from /default/category/view/id/women-like-men)
The rules for the above are:
$router->addRoute('view-category', new Zend_Controller_Router_Route(':id/category/:page', array('module' => 'default', 'controller' => 'category', 'action' => 'view', 'page' => null)));
$router->addRoute('management/category', new Zend_Controller_Router_Route('management/category/', array('module' => 'management', 'controller' => 'category', 'action' => 'index')));
There are alot of similar pages like this that "conflict" (Gallery, Movie, User) etc.
What I would really like is a rule that says /management/* route to module management/controller/action and ignore the rules below, anything with /management over rides. The likely hood of a user/gallery/movie/category being called management is low anyway.
Is it possible?
Edit, I have made this:
$router->addRoute('administration', new Zend_Controller_Router_Route_Regex('management/?(.*)/?(.*)', array('module' => 'management'), array(1 => 'controller', 2 => 'action')));
/management/category works fine, however anything after results in a 404
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这应该很简单。定义路由的顺序很重要 - 它们以相反的顺序检查,因此为了使您的管理规则“覆盖”其他规则,您希望它最后定义(即在所有其他路由之后)。像这样的东西(基本上就是你所拥有的)应该可以工作:
如果你的任何管理 URL 在此之后仍然是 404'ing,那么它们与该路由不匹配,因此它要么需要调整,要么你需要一些其他管理路由来匹配其他情况。
This should be straightforward. The order your routes are defined is important - they are checked in reverse order, so in order for your management rule to 'override' the others you want it to be defined last (i.e. after all your other routes). Something like this (which is basically what you have) should work:
If any of your management URLs are still 404'ing after this then they're not matching that route, so it either needs adjusting or you need some other management routes to match the other cases.