yii2 定义友好404

一、frontend->config->main.php添加以下:

'errorHandler' => [
            'errorAction' => 'site/error',
        ],
二、frontend->views->site->error.php中添加以下:(注:能够自行发挥制做更漂亮的404页面)


<?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>
相关文章
相关标签/搜索