How do I write chains of chains of … of route in a ini file for the Zend framework?

微笑、不失礼 提交于 2019-12-04 14:38:31

问题


I am trying to define routes as below with an INI file for the Zend Framework: http://api.example.com/servicename/{version}/users/:userid/items/:itemid

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

The host-api route works fine but when I try to reach the other routes, I get the error 'No route matched the request'

The chains.something.chains.somethingelse seems awkward so it probably isn't the correct way to do it. Anyone?


回答1:


I think I have found how to do it. Basically, you define the parts of each routes with abstract set to true and link them all with routes whose type is set to Zend_Controller_Router_Route_Chain. Something like:

[...]
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"


来源:https://stackoverflow.com/questions/2250353/how-do-i-write-chains-of-chains-of-of-route-in-a-ini-file-for-the-zend-frame

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!