如何让 Zend Route 根据域名使用不同的模块 [英] How to get Zend Route to use a different module depending on the domain name

查看:26
本文介绍了如何让 Zend Route 根据域名使用不同的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置多个域名以使用同一个框架,但我似乎无法让 zend 的路由器屈服于我的意愿.

I'd like to set up multiple domain names to use the same framework, but I can't seem to get zend's router to bend to my will.

有很多使用子域的示例,但试图让它们适用于整个域似乎并不像我期望的那样工作.

There are plenty of examples using subdomains, but trying to make them work for an entire domain doesn't seem to work as I would expect it to.

这是我最近的一次,但似乎不起作用:

Here's the closest I've come, but it doesn't seem to work:

resources.router.routes.mysite.type = "Zend_Controller_Router_Route_Hostname"
resources.router.routes.mysite.route = "www.mysite.com"
resources.router.routes.mysite.defaults.module = "mysite"

resources.router.routes.mysite1.type = "Zend_Controller_Router_Route_Hostname"
resources.router.routes.mysite1.route = "www.mysite1.com"
resources.router.routes.mysite1.defaults.module = "mysite1"

有什么建议吗?

推荐答案

基于 这个 Nabble 线程,看来您需要添加一个路径路由,然后将该路径路由链接到您的主机名路由.

Based upon this Nabble thread, it looks like you need to add a path route and then chain that path route to your hostname routes.

所以也许是这样的:

; abstract routes to be used in chaining
resources.router.routes.plain.type = "Zend_Controller_Router_Route"
resources.router.routes.plain.abstract = true
resources.router.routes.plain.route = "/:controller/:action"
resources.router.routes.plain.defaults.controller = "index"
resources.router.routes.plain.defaults.action = "index"

resources.router.routes.mysite.type = "Zend_Controller_Router_Route_Hostname"
resources.router.routes.mysite.abstract = true
resources.router.routes.mysite.route = "www.mysite.com"
resources.router.routes.mysite.defaults.module = "mysite"

resources.router.routes.mysite1.type = "Zend_Controller_Router_Route_Hostname"
resources.router.routes.mysite1.abstract = true
resources.router.routes.mysite1.route = "www.mysite1.com"
resources.router.routes.mysite1.defaults.module = "mysite1"

; now the actual (non-abstract) routes are chains of the abstract ones
resources.router.routes.mysite-plain.type = "Zend_Controller_Router_Route_Chain"
resources.router.routes.mysite-plain.chain = "mysite,plain"

resources.router.routes.mysite1-plain.type = "Zend_Controller_Router_Route_Chain"
resources.router.routes.mysite1-plain.chain = "mysite1,plain"

实际上,我们可能可以使用像 :site 这样的占位符来代替 mysiteX 值并设置一些要求,将两个抽象的 mysiteX 路由合并为一个抽象路由/defaults ,但我认为这传达了这个想法.

Actually, we could probably collapse the two abstract mysiteX routes into a single abstract route using a placeholder like :site to stand in for the mysiteX value and set some requirements/defaults on those, but I think this conveys the idea.

未测试 - 实际上我以前从未玩过链接路由 - 但似乎需要这样的东西才能使主机名路由工作.

Not tested - actually I have never played with chained routes before - but it seems that something like this is required to make the hostname routing work.

这篇关于如何让 Zend Route 根据域名使用不同的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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