zend routes ini - giving priority one rule to another or define order
I have following two rules in my routes.ini file
routes.frontcms.type = "Zend_Controller_Router_Route_Regex"
routes.frontcms.route = "/?([a-zA-Z0-9_-]+)?/?([a-zA-Z0-9_-]+)?/?([a-zA-Z0-9_-]+)?/?([a-zA-Z0-9_-]+)?"
routes.frontcms.defaults.module = frontManagement
routes.frontcms.defaults.controller = Front
routes.frontcms.defaults.action = cmspages
routes.frontcms.map.locale = 1
routes.frontcms.map.page = 2
routes.frontcms.map.subpage = 3
routes.frontcms.map.num = 4
routes.frontnoncms.type = "Zend_Controller_Router_Route_Regex"
routes.frontnoncms.route = "/?([a-z]{2}+)?/?(newsletter|contactus|accessability|search)?/?([a-zA-Z0-9_-]+)?/?([a-zA-Z0-9_-]+)?"
routes.frontnoncms.defaults.module = frontManagement
routes.frontnoncms.defaults.controller = Front
routes.frontnoncms.map.action = 2
routes.frontnoncms.map.locale = 1
routes.frontnoncms.map.page = 2
when I execute this url http://zf-cms.local/en/contactus I get following results. which is expected. it executed the second rule
Array ( [locale] => en [action] => contactus [module] => frontManagement [controller] => Front )
when I execute this url http://zf-cms.local/en/privacy_policy following are the results
Array ( [locale] => en [action] => [3] => privacy_policy [module] => frontManagement [controller] => Front )
It should execute the first rule. but because of conflict it won't able to decide which o开发者_如何学Pythonne to execute. Is there any possiblity we can define order that check second rule first and if it is not mactched then check second. some kind of priority or order?
Any one face similiar problem?
Routes are checked in reverse order so it's already working the way you want it to. Your problem is that http://zf-cms.local/en/privacy_policy does match the regular expression in your second route, so the router doesn't need to check anything else.
For reference, here's your pattern:
"/?([a-z]{2}+)?/?(newsletter|contactus|accessability|search)?/?([a-zA-Z0-9_-]+)?/?([a-zA-Z0-9_-]+)?"
so if we break that down into bits, here's how the path /en/privacy_policy
is matched:
([a-z]{2}+)/? -> matches en/
(newsletter|contactus|accessability|search)?/? -> optional, so is skipped
([a-zA-Z0-9_-]+)?/? -> matches privacy_policy
([a-zA-Z0-9_-]+)? -> optional, so is skipped
depending on how your URLs are structured the simplest solution might be to just make the second part non-optional by removing the ? after it:
"/?([a-z]{2}+)?/?(newsletter|contactus|accessability|search)/?([a-zA-Z0-9_-]+)?/?([a-zA-Z0-9_-]+)?"
精彩评论