How to set error layout in Zend Framework 2 application

Here today, I will discuss possible two way to set error layout. Lets start.

Way 1:
Put this code inside onBootstap method in Module.php.

$eventManager = $e->getApplication()->getEventManager();
$eventManager->attach(MvcEvent::EVENT_DISPATCH_ERROR, function(MvcEvent $event) {
    $viewModel = $event->getViewModel();
    $viewModel->setTemplate('layout/error-layout');
}, -200);


Way 2:

In your 404.phtml and/or error.phtml views, just simply put this code

<?php $this->layout('layout/error-layout'); ?>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s