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!

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