Created
November 24, 2012 16:03
-
-
Save joegreen88/4140295 to your computer and use it in GitHub Desktop.
Route static subdomains to controllers in zend framework
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (PHP_SAPI != 'cli') //subdomain routing | |
{ | |
$domainname = $this->getOption('domainname'); | |
$subdomains = $this->getOption('subdomains'); | |
$router = $this->bootstrap('frontController')->getResource('frontController')->getRouter(); | |
// routes for mainsite (default router is added) | |
$wwwRoute = new Zend_Controller_Router_Route_Hostname( | |
$domainname, | |
array('module' => 'default') | |
); | |
$router->addRoute( | |
'default', | |
$wwwRoute->chain( | |
new Zend_Controller_Router_Route( | |
':controller/:action/*', | |
array('controller'=>'index', 'action'=>'index') | |
) | |
) | |
); | |
// routes for subdomains (xyz.domain => subxyzController) | |
foreach ($subdomains as $subdomain) | |
{ | |
$subdomainRoute = new Zend_Controller_Router_Route_Hostname( | |
$subdomain.'.'.$domainname, | |
array('module' => 'default', 'controller'=>'sub'.$subdomain) | |
); | |
$router->addRoute( | |
$subdomain, | |
$subdomainRoute->chain( | |
new Zend_Controller_Router_Route( | |
'/:action/*', | |
array('action'=>'index') | |
) | |
) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment