2012-02-08 96 views
2

我有一個路由的博客。在我的ini它看起來像這樣:Zend Framework路由與額外的頁面參數

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

現在我想要一個頁面參數(用於評論)另外。我只通過創建像這樣的sectond路線:

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+ 

我想將這兩個合併爲一個。我怎樣才能做到這一點?頁面參數應該只是額外的。

謝謝

回答

-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" 
-1

可以分配一個defaul值頁面參數

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

+0

它只會匹配「http:// domain.com/1/1」和「http:// domain.com/1/2」。 – 2012-04-04 15:46:52

0

更改

routes.quote.route = :id

routes.quote.route = :id/*