在Yii2版本的advanced高级模板环境中:设置404自定义页面的方法
1.config/main.php文件
配置一个数组到components数组里
'errorHandler' => [
'errorAction' => 'error/error',
],
2.views/error/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>