Zend Framework subdomain+subfolder router rewrite problem
- by zf_novice
I'm new to Zend Framwork and this is an issue I've been struggling for several hours already...
I'm trying to chain Hostname and standard Route in order to get url with subdomain+subfolders ie.:
http:// lang.mydomain.com/myapplication/public/controller
http:// lang.mydomain.com/myapplication/public/controller/action
(sorry for the empty space in the address, this site won't allow links)
Basically what I have done in Bootstrap is:
// add language to default route
$routePath = new Zend_Controller_Router_Route(
':controller/:action/*',
array('controller'=>'index','action' => 'index','module'=>'default')
);
$routeHostname = new Zend_Controller_Router_Route_Hostname(
':lang.mydomain.com',
array('lang'=>$lang)
);
$frontController = $this->getResource('FrontController');
$router = $frontController->getRouter();
$router->addRoute('default', $routeHostname->chain($routePath))
$frontController->setRouter($router);
it finds the route ok, but every time I generate url in view or layout by $this-url()
<?php echo $this->url(
array(
'controller'=> 'guestbook',
'action' => 'sign',
'lang' => Zend_Registry::get('lang'),
),
'default',
true) ?>">
I get
http:// lang.mydomain.com/controller
instead of
http:// lang.mydomain.com/myapplication/public/controller
I've been trying to set baseUrl on front controller but no luck... Also I've tried the static route with myapplication/public or following standard route: 'myapplication/public/:controller/:action/*' - it result with "An error occurred Page not found Exception information: Message: No route matched the request" and empty request
Is there any way to assembly subdomain with subfolder in Zend Framwork??
EDIT:
I changed above to:
$frontController->setBaseUrl('.');
// add language to default route
$routePath = new Zend_Controller_Router_Route(
'quickstart/public/:controller/:action/*',
array(
'controller'=>'index',
'action' => 'index',
'module'=>'default',
)
);
and it works form me, although I'm not sure whether it's been correct approach...