My Error Page is not working as planned. I have an event that I create inside my Application Module
with the onBootstrap
Method that handles populating my design assets. It works on all pages except for the page where a route does not match I think its because when a dispatch error event occurs it executes all my events except for those attached by the shared event manager against Zend\Mvc\Controller\AbstractController
Here is the code for event attachment of my design event:
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);
}
Here is my event attachment inside the Application Module Bootstrap Function
for when a route does not match.
$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
);
}
}
Im fairly certain the issue has to do with me attaching the design event to the shared event manager, which must be overridden during a dispatch event error against a separate controller, although i'm not quite sure
I did recall that my design assets are linked to the specific module,controller, and action. I have in my database the route for error as application module, index controller, and not-found action
maybe this is incorrect and the design event is just not recognizing the mapped route (basically what is the correct routing information for this?)
It also seems to be producing the same result with a generic error as it shows the error/index file template but my design event did not populate the design assets.