Get module name in Zend Framework , bootstrap.php

zend-framework

I have route in bootstrap.php witch contains :

protected function _initRoutes()

{
        $router->addRoute(
            'default',
            new Zend_Controller_router_Route('/:lang/:module/:controller/:action/*',
                array('lang'=>'fa',
                        'module' => ':module',
                        'controller'=>'index',
                        'action'=>'index',
                    )
                )
        );
}

But instead of replacing module name , it returns %3module witch is url encoding of :module when i use this line :

$this->url(array('controller'=>'index','action'=>'index'),'default',true) ;

What should i do to get module name from requested URL witch is not working in _initRoutes() ?

Best Answer

Use this

$router->addRoute(
            'default',
            new Zend_Controller_router_Route('/:lang/:module/:controller/:action/*',
                array('lang'=>'fa',
                        'module' => 'default', //set the default module
                        'controller'=>'index',
                        'action'=>'index',
                    )
                )
        );

FYI: Manual

Or

Otherwise pass module name into url helper,

$module = $this->getRequest()->getModuleName();
$this->url(array('module'=>$module,'controller'=>'index','action'=>'index'),'default',true) ;
Related Topic