如何在 Zend 框架的 ini 文件中编写 ... of route 的链链? [英] How do I write chains of chains of ... of route in a ini file for the Zend framework?

查看:31
本文介绍了如何在 Zend 框架的 ini 文件中编写 ... of route 的链链?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Zend 框架的 INI 文件定义如下路由:http://api.example.com/servicename/{version}/users/:userid/items/:itemid

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

host-api 路由工作正常,但是当我尝试访问其他路由时,出现错误没有路由与请求匹配"

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

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

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

推荐答案

我想我已经找到了方法.基本上,您定义每个路由的部分,并将抽象设置为 true,并将它们与类型设置为 Zend_Controller_Router_Route_Chain 的路由链接起来.类似的东西:

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"

这篇关于如何在 Zend 框架的 ini 文件中编写 ... of route 的链链?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆