2010-02-12 42 views
4

我試圖定義路由,如下面的Zend框架的INI文件:用戶名/項目/::/用戶/ http://api.example.com/servicename/ {版本}爲itemid如何在Zend框架的ini文件中編寫路由鏈......?

routes.host.type = "Zend_Controller_Router_Route_Hostname" 
routes.host.route = "api.example.com" 

routes.host.chains.api.type = "Zend_Controller_Router_Route_Static" 
routes.host.chains.api.route = "servicename/v1" 
routes.host.chains.api.defaults.controller = "servicename-v1-api" 
routes.host.chains.api.defaults.action = "index" 

routes.host.chains.api.chains.users.chains.user.type = "Zend_Controller_Router_Static" 
routes.host.chains.api.chains.users.route = "users" 
routes.host.chains.api.chains.users.defaults.controller = "users" 
routes.host.chains.api.chains.users.defaults.action = "index" 

routes.host.chains.api.chains.users.chains.user.type = "Zend_Controller_Router_Route" 
routes.host.chains.api.chains.users.chains.user.route = ":id" 
routes.host.chains.api.chains.users.chains.user.defaults.controller = "user" 
routes.host.chains.api.chains.users.chains.user.defaults.action = "index" 
... 

主機-API航線工作正常,但當我試圖達到其他途徑,我得到的錯誤「不匹配的路由請求」

chains.something.chains.somethingelse顯得彆扭所以它可能是不這樣做的正確方法。任何人?

回答

3

我想我已經找到了如何去做。基本上,您可以定義每個路由的部分,抽象設置爲true,並將它們全部鏈接到類型設置爲Zend_Controller_Router_Route_Chain的路由。就像:

[...] 
routes.users.type = "Zend_Controller_Router_Route" 
routes.users.route = "users" 
routes.users.abstract = "1" 
routes.users.defaults.controller = "users" 
routes.users.defaults.action = "index" 

routes.host-api-users.type = "Zend_Controller_Router_Route_Chain" 
routes.host-api-users.chains = "host, api, users" 
+0

嘿,我沒有得到鏈定義的錯誤。 –