Add to your config:
'components' => ['errorHandler' => [
'errorAction' => 'site/error',
],
Create controller if not exists: SiteController.php with content:
namespace app\controllers;
use Yii;
use yii\web\Controller;
class SiteController extends Controller
{
public function actionError()
{
$exception = Yii::$app->errorHandler->exception;
if ($exception !== null) {
$this->layout = 'yourNewLayout';
return $this->render('error', ['exception' => $exception]);
}
}
}
And simplest view site/error.php:
<?php
use yii\helpers\Html;
?>
<div class="site-error">
<?= Html::encode($exception->getMessage()) ?>
</div>
Tested on Yii2. More information in documentation http://www.yiiframework.com/doc-2.0/guide-runtime-handling-errors.html#using-error-handler