4

我正在尝试使用 Zend 框架的 INI 文件定义如下路由: 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"
...

host-api 路由工作正常,但是当我尝试到达其他路由时,我收到错误“没有与请求匹配的路由”

chains.something.chains.somethingelse看起来很尴尬,所以它可能不是正确的方法。任何人?

4

1 回答 1

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"
于 2010-02-12T23:09:22.530 回答