How do you make a subdomain route for every action in a Zend Framework controller?
Using Zend Framework I want to use an account name (:account) as the subdomain that will call the basket controller. When using getParams() for the index action it does display the :account parameter but this does not work on any other actions in the basket controller.
T开发者_开发问答his is the code I currently have in the bootstrap:
$front = Zend_Controller_Front::getInstance();
$router = $front->getRouter();
$domain_name = 'domain.com';
$plainPathRoute = new Zend_Controller_Router_Route_Static('');
$hostnameRoute = new Zend_Controller_Router_Route_Hostname(
':account.' . $domain_name,
array(
'controller' => 'basket'
)
);
$router->addRoute('account', $hostnameRoute->chain($plainPathRoute));
Thanks in advance for your help and guidance.
You actually need two chained routes:
- Your subdomain route
- A route responsible for everything after your domain
I use this config to set up a route this (although I map all subdomains to modules, but i guess you can fix this ;):
'subdomain' => array(
'type' => 'Zend_Controller_Router_Route_Hostname',
'route' => ':module.localhost',
'chains' => array(
'index' => array(
'type' => 'Zend_Controller_Router_Route',
'route' => ':controller/:action/*'
)
)
)
精彩评论