0

I have the following code in my bootstrap. It works well, however, with any module besides default it redirects to the default module. How can I get this to to work with modules besides the default module?

protected function _initRoutes()
{
    $this->bootstrap(array('FrontController'));
    $router = $this->getResource('Frontcontroller')->getRouter();
    $router->removeDefaultRoutes();
    $language = new Zend_Controller_Router_Route(
         ':language', array('language' =>'en')
    );
    $module = new Zend_Controller_Router_Route_Module(
      array(
      'module'    => 'default',
      'controller'=> 'index',
              'action'    => 'index'
       ),
       Zend_Controller_Front::getInstance()->getDispatcher(),
       Zend_Controller_Front::getInstance()->getRequest()
    );
    $module->isAbstract(true);
    $default = new Zend_Controller_Router_Route_Chain();
    $default->chain($language);
    $default->chain($module);
    $router->addRoute('default', $default);
}
somejkuser
  • 8,856
  • 20
  • 64
  • 130

1 Answers1

1

Here is and example how to chain language route with default route working with different modules.

You should not specify the module to 'default' in your $module route

$module = new Zend_Controller_Router_Route_Module(
   array(),
   Zend_Controller_Front::getInstance()->getDispatcher(),
   Zend_Controller_Front::getInstance()->getRequest()
);
Elena Slavcheva
  • 126
  • 2
  • 10
  • Works perfectly. The only question I have is I want to perform a redirect to `url/:language` if we are at the base path and there is no `:language` in the URL. How do I accomplish this? – somejkuser Mar 25 '13 at 14:29
  • You can use the view helper or action helper url and pass the language as a parameter. E.g. `=$this->url(array("language" => "fr"), null, true)?>` – Elena Slavcheva Mar 26 '13 at 07:41