Php preDispatch zend framework 2不工作

Php preDispatch zend framework 2不工作,php,zend-framework2,Php,Zend Framework2,我在理解preDispatch时遇到问题。下面是我的代码 public function preDispatch(\Zend\Mvc\MvcEvent $e) { $application = $e->getApplication(); $serviceManager = $application->getServiceManager(); $controller = $e->getTarget();

我在理解preDispatch时遇到问题。下面是我的代码

 public function preDispatch(\Zend\Mvc\MvcEvent $e)
    {

        $application    = $e->getApplication();
        $serviceManager = $application->getServiceManager();
        $controller = $e->getTarget();
        $route = $controller->getEvent()->getRouteMatch();
        $hit_controller = $route->getParam('__CONTROLLER__');
        if(strcmp($hit_controller,"Dashboard")==0){
            $authService = $serviceManager->get('Admin\Authentication\Service');
            if (!$authService->hasIdentity()) {
                $pluginManager  = $serviceManager->get('Zend\Mvc\Controller\PluginManager');
                $redirectPlugin = $pluginManager->get('redirect');
                return $redirectPlugin->toRoute('Admin',array('controller'=>'Admin','action'=>'index'));
            }
        }
        return;
    } 
下面是module.config.php中定义的路由

return array(
    'router' => array(
        'routes' => array(
            'Dashboard' => array(
              'type' => 'Segment',
              'options' => array(
                  'route' => '/Dashboard[/:action][/:id]',
                  'defaults' => array(
                      '__NAMESPACE__' => 'Admin\Controller',
                        'controller'    => 'Dashboard',
                        'action'        => 'index',
                  ),

              ),

            ),
            'Admin' => array(
                'type'    => 'Segment',
                'options' => array(
                    'route'    => '/Admin[/:action][/:id]',
                    'defaults' => array(
                        '__NAMESPACE__' => 'Admin\Controller',
                        'controller'    => 'Admin',
                        'action'        => 'index',
                    ),
                ),
            ),
        ),
    ),
    'controllers' => array(
        'invokables' => array(
            'Admin\Controller\Admin' => 'Admin\Controller\AdminController',
            'Admin\Controller\Dashboard' => 'Admin\Controller\DashboardController'
        ),
    ),
    'view_manager' => array(  ),
        'template_path_stack' => array(
            __DIR__ . '/../view',
        ),
    ),
);
如果我输入url

public/Admin works fine
 public/Dashboard works fine
 public/Dashboard/edit works fine
 public/Dashboard/edit/11  fails
并显示编辑/11的内容。我不明白为什么preDispatch不能在Dashboard/edit/11上运行


请有人给我灯光和指引方向好吗。高度重视任何建议/意见/hlep。谢谢

尝试按如下方式更改仪表板路线中的括号:

'route' => '/Dashboard[/:action[/:id]]',