Zend Routing Issues

I read all the routing and Zend Documentation messages, but I still cannot solve this problem.

I have a multilingual application with two modules: default and admin. Selecting the language works fine (in the Controller routeShutdown plugin), but I have some problems setting up the router:

I want this URL to work:

/
/controller
/controller/action
/action                  (default controller)
/controller/param        (default action)
/admin
/admin/admin-controller
/admin/admin-controller/action

and using the language selector it will be:

/en
/en/controller
/en/controller/action
/en/action                  (default controller)
/en/controller/param        (default action)
/en/admin/admin-controller
/en/admin/admin-controller/action

I added this to my bootstap file (index.php):

$frontController = Zend_Controller_Front::getInstance();
$router = $frontController->getRouter();
$router->removeDefaultRoutes();
$router->addRoute('langmodcontrolleraction',

new Zend_Controller_Router_Route('/:lang/:module/:controller/:action',
    array('lang' => ':lang'))
);

$router->addRoute('langmodcontroller',
new Zend_Controller_Router_Route('/:lang/:module/:controller',
    array('lang' => ':lang',
        'action' => 'index'))
);

$router->addRoute('langmod',
new Zend_Controller_Router_Route('/:lang/:module',
    array('lang' => ':lang',
        'action' => 'index',
        'controller' => 'index'))
);

$router->addRoute('lang',
new Zend_Controller_Router_Route('/:lang',
    array('lang' => ':lang',
        'action' => 'index',
        'controller' => 'index',
        'module' => 'default'))
);

$frontController->setControllerDirectory(array(
'default'=>BASE_PATH.'app/modules/default/controllers',
'admin'=>BASE_PATH.'app/modules/admin/controllers'));    

To test how the router parses the URL, I added var_dump to the routeShutdown plan:

Entering / ru , I get:

array
'lang' => string 'en' (length=2)
'action' => string 'index' (length=5)
'controller' => string 'index' (length=5)
'module' => string 'default' (length=7)

which is fine. But when I enter / en / controller1 , I get:

array
'lang' => string 'en' (length=2)
'module' => string 'controller1' (length=8)
'action' => string 'index' (length=5)
'controller' => string 'index' (length=5) 

"controller1". ? URL-, /en/controller/param? ( )

+5
1

, URL- , , ZF.

-, , , ; , , URL- . , , , . /en/controller, /:lang, . /:lang/:module, , /:lang/:module //, .

:

/en/controller
/en/action

, URL-, /en/foo, , .

/, , - , :

$router->addRoute('langmod', new Zend_Controller_Router_Route(
    '/:lang/:module', 
    array(
        'lang' => ':lang',
        'action' => 'index',
        'controller' => 'index'
    ),
    array(
        'module' => '(foo|bar|something)'
    )
));

foo, bar .. . , /en/controller1, , 1 , :. /:lang/:controller (, , /:lang/:controller/:action), .

, . , / , . langmodcontroller :

$router->addRoute('langmodcontroller',new Zend_Controller_Router_Route(
    '/:lang/:module/:controller',
    array(
        'lang' => ':lang',
        'controller' => 'index'
        'action' => 'index' 
    )
));

. , , /en/blog lang = en, module = blog, controller = index, action = index. /en/blog/index/foo ​​ = blog, controller = index, action = foo. , , = - URL. , , URL- ( ​​ ), - , .

- ( ):

/:lang/:controller/:action/ (with 'index' defaults for controller and action)
/:lang/:action (with 'action' restricted to some predefined values)
/:lang/admin/:controller/:action (with 'admin' as a string in the URL, and :module set to 'admin' as the default)

URL-:

/en
/en/controller
/en/controller/action
/en/action
/en/controller/param
/en/admin/controller
/en/admin/controller/action

.

ZF , .

+6

All Articles