Zend Framework unknown module is interpreted as default module

345 views Asked by At

i wanted to support multilingual structure for my work i used the following lines

$controller=Zend_Controller_Front::getInstance();
$router=$controller->getRouter();
$languageRouter=new Zend_Controller_Router_Route(":lang/:module/:controller/:action", array("lang"=>"en","module"=>"default","controller"=>"index","action"=>"index"),
                                                array("lang"=>"[a-zA-Z]{2}"));
$router->addRoute("default",$languageRouter);

it works fine http://localhost/zend/public/en set the lang param to en and call default module but the problem is that when i use url like this http://localhost/zend/public/en/anything where anything isn't module it still show the default module how to prevent that???


after the answer of takeshin i added this function to the bootstarp file and now it works as i want it

protected function _initRoutes()
{
    $routeLang=new Zend_Controller_Router_Route(':lang',array('lang'=>'en'),array('lang'=>'[a-z]{2}'));
    $front  = Zend_Controller_Front::getInstance() /*$this->getResource('frontcontroller')*/;
    $router = $front->getRouter();
    $routeDefault=new Zend_Controller_Router_Route_Module(array(),$front->getDispatcher(),$front->getRequest());
    $routeLangDefault=$routeLang->chain($routeDefault);
    $router->addRoute('default',$routeLangDefault);
    $router->addRoute('lang',$routeLang);
}
3

There are 3 answers

0
takeshin On BEST ANSWER

It looks like you have overwritten default module defined in Zend Application by your custom one.

You should chain the routes instead.

1
Shaun Hare On

The settings you are using means module will 'default' to default , if you didn't it would throw a route not found error - which should throw to appropriate error controller

1
MakG On

I'm not sure if I unterstood this correctly, but it looks like it works fine, as it should. If you try to call non existing module, Zend Framework automatically "redirects" to the default module.