如何在 Zend 框架的 ini 文件中编写路由链……的链?

发布于 2024-08-21 04:55:43 字数 1265 浏览 10 评论 0原文

我正在尝试使用 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"
...

主机 api 路由工作正常,但当我尝试访问其他路由时,出现错误“没有与请求匹配的路由”

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

七分※倦醒 2024-08-28 04:55:43

我想我已经找到了该怎么做。基本上,您定义每个路由的部分,并将 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"

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"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文