我的错误页面无法按计划工作。我在Application Module
内部使用onBootstrap
方法创建了一个事件,该事件用于处理设计资产。 它适用于除路由不匹配的页面之外的所有页面 ,因为发生调度错误事件时,它会执行我的所有事件,但共享事件管理器针对{{1 }}
这是我的设计事件的事件附件代码:
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
);
}
}
可能不正确,而设计事件只是无法识别映射的路由(基本上正确的路由信息是什么?)
它似乎也产生了相同的错误,但它显示了错误/索引文件模板,但我的设计事件并未填充设计资产。
答案 0 :(得分:-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);
}