How to get Zend Route to use a different module de

2020-04-19 07:08发布

问题:

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"

Any suggestions?

回答1:

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.



回答2:

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.