Jump to content

Archived

This topic is now archived and is closed to further replies.

shlumph

Dynamic Subdomains & Zend_Controller_Router_Route_Hostname?

Recommended Posts

I am having some trouble creating dynamic subdomains. The idea is to route the following URL:

asdf.budget.com to www.budget.com/test/index/asdf

 

I have setup a Controller Plugin:

<?php
class Rob_Controller_Plugin_Route extends Zend_Controller_Plugin_Abstract
{
    public function routeStartup(Zend_Controller_Request_Abstract $request)
    {
    	//http://framework.zend.com/manual/en/zend.controller.router.html#zend.controller.router.routes.hostname
        //http://www.noginn.com/2008/09/03/using-subdomains-as-account-keys/
        $front = Zend_Controller_Front::getInstance();
        $router = $front->getRouter();
	$router->removeDefaultRoutes();

	$pathRoute = new Zend_Controller_Router_Route(
	    ':controller/:action/*',
	    array(
	        'controller' => 'index',
	        'action' => 'index'
	    )
	);

	$adminRoute = new Zend_Controller_Router_Route_Hostname(
	    ':test.budget.com',
	    array(
	        'controller' => 'test',
	        'action' => 'index'
	    )
	);
	$router->addRoute('test', $adminRoute->chain($pathRoute));

	$defaultRoute = new Zend_Controller_Router_Route_Hostname(
	    'www.budget.com',
	    array(
	        'module' => 'default',
	    )
	);
	$router->addRoute('default', $defaultRoute->chain($pathRoute));

}
}

 

And connect it in my applications.ini file:

resources.frontController.plugins.Route = "Rob_Controller_Plugin_Route"; 

 

However, it's not routing to the test controller and index action when I enter in a subdomain. Anyone see what's wrong here? Any help is greatly appreciated.

Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.