1
我有以下理解preDispatch問題是我的代碼preDispatch Zend框架2不工作
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
並顯示edit/11的內容。我不明白爲什麼preDispatch不能在Dashboard/edit/11上運行?
有人可以投光並指引正確的方向。任何建議/意見/ hlep都受到高度重視。感謝
不行,還是要謝謝你的幫助 –