提问人:somejkuser 提问时间:7/27/2018 最后编辑:somejkuser 更新时间:8/3/2018 访问量:252
Dispatch 错误事件未连接到 AbstractController 上的共享事件
Dispatch Error Event Not Connecting to Shared Event on AbstractController
问:
我的错误页面未按计划工作。我有一个事件,我在我的内部创建了一个事件,该事件使用处理填充我的设计资产的方法。它适用于除路由不匹配的页面之外的所有页面我认为这是因为当发生调度错误事件时,它会执行我的所有事件,除了共享事件管理器附加的事件Application Module
onBootstrap
Zend\Mvc\Controller\AbstractController
以下是我的设计事件的事件附加代码:
public function attach(EventManagerInterface $events,$priority=10) {
$events->getSharedManager()->attach('Zend\Mvc\Controller\AbstractController',
MvcEvent::EVENT_DISPATCH,[$this,'initiateAssets'],1000);
$events->getSharedManager()->attach('Zend\Mvc\Controller\AbstractController',
MvcEvent::EVENT_DISPATCH,[$this,'changeLayout'],30);
$events->getSharedManager()->attach('Zend\Mvc\Controller\AbstractController',
MvcEvent::EVENT_DISPATCH,[$this,'loadJsAssets'],30);
$events->getSharedManager()->attach('Zend\Mvc\Controller\AbstractController',
MvcEvent::EVENT_DISPATCH,[$this,'loadCssAssets'],30);
$events->getSharedManager()->attach('Zend\Mvc\Controller\AbstractController',
MvcEvent::EVENT_DISPATCH,[$this,'loadMetatagAssets'],30);
$events->getSharedManager()->attach('Zend\Mvc\Controller\AbstractController',
MvcEvent::EVENT_DISPATCH,[$this,'setupNavigation'],30);
}
这是我在路由不匹配时的事件附件。Application Module Bootstrap Function
$eventManager->attach(
\Zend\Mvc\MvcEvent::EVENT_DISPATCH_ERROR,
function ($e) {
$application = $e->getApplication();
$serviceLocator = $application->getServiceManager();
$match = $application->getMvcEvent()->getRouteMatch();
if (null === $match) {
$uri = $e->getRequest()->getUri();
$params = [
'__NAMESPACE__' => 'Application\Controller',
'controller' => 'Application\Controller\IndexController',
'action' => 'not-found',
'locale' => 'en_US'
// Here you can add common params for your application routes
];
$routeMatch = new \Zend\Router\Http\RouteMatch($params);
$routeMatch->setMatchedRouteName('notFound');
$application->getMvcEvent()->setRouteMatch(
$routeMatch
);
}
}
我相当确定该问题与我将设计事件附加到共享事件管理器有关,尽管我不太确定,但在针对单独控制器的调度事件错误期间必须覆盖该事件管理器
我确实记得我的设计资产链接到特定的模块、控制器和操作。我的数据库中有错误的路由,因为这可能是不正确的,并且设计事件只是无法识别映射的路由(基本上正确的路由信息是什么?application module, index controller, and not-found action
它似乎也产生了相同的结果,并出现了一个通用错误,因为它显示了错误/索引文件模板,但我的设计事件没有填充设计资产。
答:
-1赞
ebelair
8/3/2018
#1
您是否尝试附加EVENT_DISPATCH_ERROR:
public function attach(EventManagerInterface $events,$priority=10) {
$events->getSharedManager()->attach('Zend\Mvc\Controller\AbstractController',
MvcEvent::EVENT_DISPATCH_ERROR,[$this,'initiateAssets'],1000);
$events->getSharedManager()->attach('Zend\Mvc\Controller\AbstractController',
MvcEvent::EVENT_DISPATCH_ERROR,[$this,'changeLayout'],30);
$events->getSharedManager()->attach('Zend\Mvc\Controller\AbstractController',
MvcEvent::EVENT_DISPATCH_ERROR,[$this,'loadJsAssets'],30);
$events->getSharedManager()->attach('Zend\Mvc\Controller\AbstractController',
MvcEvent::EVENT_DISPATCH_ERROR,[$this,'loadCssAssets'],30);
$events->getSharedManager()->attach('Zend\Mvc\Controller\AbstractController',
MvcEvent::EVENT_DISPATCH_ERROR,[$this,'loadMetatagAssets'],30);
$events->getSharedManager()->attach('Zend\Mvc\Controller\AbstractController',
MvcEvent::EVENT_DISPATCH_ERROR,[$this,'setupNavigation'],30);
}
评论