1
動態可變Zend框架2 onBootstrap重定向我在Module.php文件,該文件看起來像onBootstrap功能重定向:與路線
$url = $e->getRouter()->assemble(array(), array('name' => 'administrator/error/acl')); // redirect to this URL
$response=$e->getResponse();
$response->getHeaders()->addHeaderLine('Location', $url);
$response->setStatusCode(302);
$response->sendHeaders();
// stop further execution
$stopCallBack = function($event) use ($response){
$event->stopPropagation();
return $response;
};
$e->getApplication()->getEventManager()->attach(MvcEvent::EVENT_ROUTE, $stopCallBack,-10000);
return $response;
雖然路由配置看起來像這樣(管理員定義和正常工作與其他途徑):
'error'=> array(
'type' => 'Segment',
'options' => array(
'route' => '/error',
'defaults' => array(
'controller' => 'MyAdmin\Controller\Error',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'error_name' => array(
'type' => 'Segment',
'options' => array(
'route' => '/[:error_name]',
'constraints' => array(
'error_name' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
'action' => 'index',
),
),
'may_terminate' => true
),
),
),
當它設法重新出現以下錯誤:
Fatal error: Uncaught exception 'Zend\Mvc\Router\Exception\RuntimeException' with message 'Route with name "acl" not found' in......
我在做什麼錯?
添感謝您的回覆! error_name參數將決定向用戶顯示哪個錯誤消息。 「acl」只意味着顯示錯誤消息,指出用戶無權訪問所選頁面。我試過你的解決方案,但無法使其工作。我試過了:$ url = $ e-> getRouter() - > assemble(array(),array('name'=>'administrator/error/error_name','error_name'=>'administrator/error/acl') );它將我重定向到「/ administrator/error /」。最後一個參數被自動刪除... – gtsongi 2014-10-03 09:00:21