路由器zend框架1.11中的动态控制器

时间:2012-09-08 22:49:48

标签: zend-framework frameworks controller router

如何在路线中工作多个控制器? 我的路线:

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

此路由适用于索引控制器,但不适用于auth控制器。 如何使用该路由和索引auth控制器?

我的菜单项:

$this->url(array('controller'=>'Auth','action'=>'index')

此菜单项无效。 我的完整功能_initRoutes()

protected function _initRoutes(){

    $frontController = Zend_Controller_Front::getInstance();
    $router = $frontController->getRouter();
    $router->removeDefaultRoutes();
    $router->addRoute(
            'fullRoute',
            new Zend_Controller_Router_Route('/:lang/:module/:controller/:action',
                    array('lang' => ':lang')
            )
    );
    $router->addRoute(
            'languageControllerAction',
            new Zend_Controller_Router_Route('/:lang/:controller/:action',
                    array('lang' => ':lang')
            )
    );

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

}

我需要控制器身份验证的行动路线。

1 个答案:

答案 0 :(得分:0)

路线#1

这会将http://yoursite.com/auth指向default模块,AuthControllerindexAction

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

路线#2

这会将http://yoursite.com/指向default模块,AuthControllerindexAction

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