dream2891 2013-04-17 16:48
浏览 33
已采纳

Zend_Controller_Router_Route_Regex和分页问题

I speak English not well, so sorry.

The code.

routers.ini:

routes.cat1.type = "Zend_Controller_Router_Route_Regex"
routes.cat1.route = "showcat/(\d+)-(\d+)"
routes.cat1.defaults.module = "default"
routes.cat1.defaults.controller = "category"
routes.cat1.defaults.action = "viewcategory"
routes.cat1.map.1 = "id1"
routes.cat1.map.2 = "page"
routes.cat1.reverse = "showcat/%d-%d"

When i visit:

showcat/6

It returns error: Invalid controller specified (showcat)

But when i visit:

showcat/6-1

It works fine.

When i add following router to fix above problem:

routes.cat2.type = "Zend_Controller_Router_Route_Regex"
routes.cat2.route = "showcat/(\d+)"
routes.cat2.defaults.module = "default"
routes.cat2.defaults.controller = "category"
routes.cat2.defaults.action = "viewcategory"
routes.cat2.map.1 = "id1"
routes.cat2.reverse = "showcat/%d"

but the pagination doesn't work.

Can anyone help me solve this problem?

Thanks!

  • 写回答

1条回答 默认 最新

  • drnysdnnb2909701 2013-04-17 21:27
    关注

    Firsrly, I would use a forward slash instead of a dash:

    routes.cat2.route = "showcat/(\d+)/(\d+)"

    But, in either case, you're regex needs to know if the second statement doesn't exist, so:

    routes.cat2.route = "showcat/(\d+)(?:/(\d+))?"

    Or, with a dash:

    routes.cat2.route = "showcat/(\d+)(?:-(\d+))?"

    Note the question marks - indicated whether or not the item HAS to be be there.

    Remember to set a default for the second parameter in your route:

    routes.cat2.route.defaults.2 = 1

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?