y284663247 2019-07-31 09:13:18 1675次浏览 0条回复 0 0 0

一共三步,首先在对应模板的 Module.php 指定 errorAction,然后实现 error 方法,最后添加新视图文件

首先在 h5/Module.php 里面 init() 方法里,添加如下程序

Yii::$app->errorHandler->errorAction =  'h5/default/error'; //这个是路由,我设置的是h5模块下的Default控制器的error方法

然后在h5的DefaultController里面实现error方法

 public function actionError(){
    $exception = Yii::$app->errorHandler->exception;
    if ($exception !== null) {
        return $this->render('error', ['exception' => $exception]);
    }
}

最后,在 views/error.php里面添加对应变量

<?php

/* @var $this yii\web\View */
/* @var $name string */
/* @var $message string */
/* @var $exception Exception */

$this->title = $exception->getMessage();
?>
<div class="error-content">
    <h3 class="tc">发生错误</h3>
    <div class="alert alert-danger">
        <?= $exception->getMessage()?>
    </div>
</div>
    没有找到数据。
您需要登录后才可以回复。登录 | 立即注册