dsxcv5652 2010-09-21 11:01
浏览 49
已采纳

Zend路由器优先

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+

; searchroute
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.

  • 写回答

2条回答 默认 最新

  • dongniaoli1822 2010-09-29 22:23
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?