2014-02-13 137 views
0

我在Zend Framework 2中有一个关于树路由的问题,我希望你能帮助我。Zend框架中的树路由2

我在建立模块管理员。当我登录时,它将运行AdministratorController的loginAction。当我登录成功时,它将转到AdministratorController的indexAction。我完成了这个。

zf2exam.loc /管理员--->登录 - >登录成功 - > zf2exam.loc /管理/ index.php文件

所以,当我登录成功,我要管理模块管理的所有控制器。我必须如何路由到模块管理员中的另一个控制器?例如:zf2exam.loc/Administrator/News/Update/1。感谢您的收看。非常感谢。

return array(
'controllers' => array(
    'invokables' => array(
     'Admin\Controller\Admin' => 'Admin\Controller\AdminController', 
     'Admin\Controller\News' => 'Admin\Controller\NewsController', 
    ), 
), 
'router' => array(
    'routes' => array(
     'admin' => array(
      'type' => 'Segment', 
      'options' => array(
       'route' => '/admin[/:action][/:id]', 
       'defaults' => array(
        '__NAMESPACE__' => 'Admin\Controller', 
        'controller' => 'admin', 
        'action' => 'login', 
       ), 
      ), 
      'may_terminate' => true, 
      'child_routes' => array(
       'default' => array(
        'type' => 'Segment', 
        'options' => array(
         'route' => '/[:controller[/:action]]', 
         'constraints' => array(
          'controller' => '[a-zA-Z][a-zA-Z0-9_-]*', 
          'action' => '[a-zA-Z][a-zA-Z0-9_-]*', 
         ), 
         'defaults' => array(
          'controller' => 'about', 
          'action' => 'index', 
         ), 
        ), 
       ), 
      ), 
     ), 
    ), 
), 
'view_manager' => array(
    'template_path_stack' => array(
     'doctype' => 'HTML5', 
     'admin' => __DIR__ . '/../view', 
    ), 
), 

);

回答

0

我无法测试,但我会做这样的事情:

'router' => array(
    'routes' => array(
     'admin' => array(
      'type' => 'Litteral', 
      'options' => array(
       'route' => '/Administrator', 
       'defaults' => array(
        '__NAMESPACE__' => 'Admin\Controller', 
        'controller' => 'Admin', 
        'action' => 'login', 
       ), 
      ), 
      'may_terminate' => true, 
      'child_routes' => array(
       'default' => array(
        'type' => 'Segment', 
        'options' => array(
         'route' => '/:controller[/:action[/:id]]', 
         'constraints' => array(
          'controller' => '[a-zA-Z][a-zA-Z0-9_-]+', 
          'action' => '[a-zA-Z][a-zA-Z0-9_-]+', 
          'id' => '[0-9]+', 
         ), 
         'defaults' => array(
          'controller' => 'Admin', 
          'action' => 'index', 
         ), 
        ), 
       ), 
      ), 
     ), 
    ), 
),