How to map sub domain to a module directory in Zend framework?

We will today try and configure a sub domain to point to a module directory in zend framework. Those who have worked on modules in Zend framework will know that Zend builds a separate folder for a module which will have it’s own controllers, views, helpers etc. In effect you will be able to modularize your application through the use of modules. We are simply trying to map a sub domain so that you can access your module by simply typing

subdomain.domainname.com

instead of

www.domainname.com/modulename

So, just open your application.ini file in your application/configs folder and enter the following lines in the section related to your server environment.

resources.router.routes.user.type = "Zend_Controller_Router_Route_Hostname"
resources.router.routes.user.route = "subdomain.domainname.com"
resources.router.routes.user.defaults.module = "modulename"
resources.router.routes.user.chains.index.type = "Zend_Controller_Router_Route"
resources.router.routes.user.chains.index.route = ":controller/:action/*"
resources.router.routes.user.chains.index.defaults.controller = "controllername"
resources.router.routes.user.chains.index.defaults.action = "actionname"

From above,

subdomain.domainname.com = the actual sub domain you wish to map to your module.
modulename = the name of the module
controllername = the name of the controller which would be loaded by default when the sub domain is browsed
actionname = is the name of the action within the controller which would be called by default when the sub domain is browsed

Please follow and like us:

Be the first to comment

Leave a Reply

Your email address will not be published.


*