How to get Zend Route to use a different module depending on the domain name

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-02 03:14:40

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.

So perhaps something like:

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

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.

I've done this before by actually using different configuration files based on the current value of $_SERVER['SERVER_NAME'], which is configured by the web server. (HTTP_HOST is the one sent by the client.)

You could probably do the same thing in a single file by using INI file sections and inheritance.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!