You can do this by help of module.php
public function onBootstrap (EventInterface $event)
{
$eventManager->getSharedManager()->attach('*', MvcEvent::EVENT_DISPATCH, array($this, 'onDispatchError'), -100);
$eventManager->getSharedManager()->attach('*', MvcEvent::EVENT_DISPATCH_ERROR, array($this, 'onDispatchError'), -100);
$eventManager->getSharedManager()->attach('*', MvcEvent::EVENT_RENDER_ERROR, array(
$this,
'onDispatchError'
), - 100);
}
public function onDispatchError(MvcEvent $event){
$response = $event->getResponse();
if ($response->getStatusCode() == 404) {
$vm = $event->getViewModel(); $vm->setTemplate('layout/custom_404');
//DO SOMETHING
$event->getViewModel();
} elseif($response->getStatusCode() == 500){ $vm = $event->getViewModel(); $vm->setTemplate('layout/custom_500');
$event->getViewModel(); //DO SOMETHING else?
}
}
How to Disable error page layout in zf2 .
$eventManager = $e->getApplication()->getEventManager();
$eventManager->attach(MvcEvent::EVENT_DISPATCH_ERROR, function($e) {
$result = $e->getResult();
$result->setTerminal(TRUE);
});
Comments
Post a Comment