参考文档: http://www.yiifans.com/yii2/guide/runtime-handling-errors.html
yii 自身带的错误提示已经很棒了 但是有些时候还是需要嵌入自己的错误提示页面:
目的: 修改404的页面的显示的效果 ,其他的错误码显示不变
过程:
用专门的控制器动作渲染错误页面, 在views/site/error 借用 $exception->statusCode === 404 引入单独设计的页面
备注:
原本的view/error.php
<?php use yii\helpers\Html; $this->title = $name; $this->context->layout = false; //不使用布局 ?> <div class="site-error"> <h1><?= Html::encode($this->title) ?></h1> <div class="alert alert-danger"> <?= nl2br(Html::encode($message)) ?> </div> </div>