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

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

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料