带有附加页面参数的Zend Framework Routing

时间:2012-02-08 21:39:03

标签: php zend-framework zend-route

我有一个带路由的博客。在我的ini中,它似乎是这样的:

routes.quote.route = :id
routes.quote.defaults.module = default
routes.quote.defaults.controller = posts
routes.quote.defaults.action = single
routes.quote.reqs.id = \d+

现在我想要一个页面参数(用于评论)。我只是通过创建这样的路径来获得它:

routes.quotePage.route = :id/page/:page
routes.quotePage.defaults.module = default
routes.quotePage.defaults.controller = posts
routes.quotePage.defaults.action = single
routes.quotePage.reqs.id = \d+
routes.quotePage.reqs.page = \d+

我想将这两者合二为一。我怎样才能做到这一点? page-parameter应该只是附加的。

谢谢

3 个答案:

答案 0 :(得分:0)

更改

routes.quote.route = :id

routes.quote.route = :id/*

答案 1 :(得分:-1)

像这样使用Zend_Controller_Router_Route_Regex

routes.quote.route.type = "Zend_Controller_Router_Route_Regex"
routes.quote.route = posts/(\d+)/(\d+)
routes.quote.defaults.module = default
routes.quote.defaults.controller = posts
routes.quote.defaults.action = single
routes.quote.map.1 = "id"
routes.quote.map.1 = "page"

答案 2 :(得分:-1)

您可以为页面参数

指定默认值
routes.quotePage.route = :id/:page
routes.quotePage.defaults.module = default
routes.quotePage.defaults.controller = posts
routes.quotePage.defaults.action = single
routes.quotePage.defaults.page = 1
routes.quotePage.reqs.id = \d+
routes.quotePage.reqs.page = \d+

这将匹配http://domain.com/1http://domain.com/1/page/1http://domain.com/1/page/2