我正在尝试使用Zend Framework的INI文件定义如下路由: http://api.example.com/servicename/ {版本} /用户/:用户ID /项目/:为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"
...
host-api路由工作正常但是当我尝试到达其他路由时,我收到错误“没有路由匹配请求”
chains.something.chains.somethingelse 似乎很尴尬,所以它可能不是正确的方法。任何人吗?
答案 0 :(得分:3)
我想我已经找到了怎么做。基本上,您将每个路由的部分定义为abstract设置为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"