[置頂] YII2 模塊內自定義錯誤頁

當前YII框架中把錯誤異常配置都放置在 web.php 中,對於新增的模塊 module 非常不方便,而且文檔中基本沒有任何教程,此處給大家分享一個方法:

<?php

namespace app\modules\cangshu;

class Module extends \yii\base\Module
{
    public $controllerNamespace = 'app\modules\cangshu\controllers';

    public function init()
    {
        parent::init();

        // \Yii::configure($this->module, require(__DIR__ . '/config.php'));
        
        // 自定義錯誤頁
        \Yii::$app->errorHandler->errorAction = 'cangshu/error/view';
    }
}

希望對大家有用,更多內容請看我博客: http://vb2005xu.iteye.com

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章