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!

我说英语不太好,很抱歉。 strong> em>

代码。 p>

routers.ini: p>

  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”
   pre> 
 
 

当我访问时: p>

  showcat / 6 
  code>  pre> 
 
 它返回错误:指定的控制器无效(showcat) strong>  p> 
 
 

但是当我访问时: p>

  showcat  / 6-1 
  code>  pre> 
 
 

工作正常。 p>

当我添加以下路由器来修复上述问题时: p>

  routes.cat2.type =“Zend_Controller_Router_Route_Regex”
routes.cat2.route =“showcat /(\ d +)”
 
uroutes.cat2.defaults.module =“default”
routes.cat2  .defaults.controller =“c  ategory“
routes.cat2.defaults.action =”viewcategory“
routes.cat2.map.1 =”id1“
routes.cat2.reverse =”showcat /%d“
  code>  pre> \  n 
 

但是分页不起作用。 p>

任何人都可以帮我解决这个问题吗? p>

谢谢! p> div>

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