开发者

Zend Router precedence

开发者 https://www.devze.com 2023-01-16 20:05 出处:网络
I have got two routes ; category route resources.router.routes.category.type = \"Zend_Controller_Router_Route\"

I have got two routes

; category route
resources.router.routes.category.type = "Zend_Controller_Router_Route"
resources.router.routes.category.route = "shopping/:idTwo/:id/*"
resources.router.routes.category.defaults.module = "default"
resources.router.routes.category.defaults.controller = "shopping"
resources.router.routes.category.defaults.action = "category"
resources.router.routes.category.reqs.id = \w+
resources.router.routes.category.reqs.id = \d+

; searchrou开发者_StackOverflow中文版te
resources.router.routes.search.type = "Zend_Controller_Router_Route"
resources.router.routes.search.route = "shopping/search/:id/*"
resources.router.routes.search.defaults.module = "default"
resources.router.routes.search.defaults.controller = "shopping"
resources.router.routes.search.defaults.action = "search"
resources.router.routes.search.reqs.id = \w+

Category route must match with urls like http://mrc.localhost/shopping/Childrens-Clothing/98 and it is working fine

Search route must match with urls like http://mrc.localhost/shopping/search/dvd+box+set and http://mrc.localhost/shopping/search/123.

Search route is working fine for url that dont have keyword(:id) as an integer like http://mrc.localhost/shopping/search/dvd+box+set but if keyword is just integer then category router took precende like for urls http://mrc.localhost/shopping/search/123 and therefore category action is called instead of search action because you see :idTwo can be any string and it matches "search" therefore category route is used but I want search route to be used no matter what is the keyword.


Routes are actually matched in REVERSE order, so put your more specific routes on the bottom, and more generic ones on top. Your order is fine.

When I tested, I found that the search URL with the ID (123) works fine, but the other one ('dvd+box+set') does not work. You are requiring :id to be \w+ -- the + in 'dvd+box+set' is what is causing it to fail.

If you want search/* to go to the search action, ditch the requirement, and do something more with it in your action controller code if you must, otherwise non \w+ ids will cause it to go to the category route.

Cheers


Try putting searchroute definition before category route definition in your config file.

The idea is that more specific routes (searchroute in your case) should precede more general routes (category route).

0

精彩评论

暂无评论...
验证码 换一张
取 消