开发者

Zend Framework unknown module is interpreted as default module

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(),$fro开发者_如何学运维nt->getDispatcher(),$front->getRequest());
    $routeLangDefault=$routeLang->chain($routeDefault);
    $router->addRoute('default',$routeLangDefault);
    $router->addRoute('lang',$routeLang);
}


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

You should chain the routes instead.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜