小编pup*_*oyo的帖子

Yii2,模块错误页面未显示但在错误404时显示空白页面

我已经尝试actionError在模块DefaultController中编写自己的,只是为了呈现错误页面(HTML仅用于测试),它也只是显示空白页面而不是显示错误页面.

我在下面做正确的方法吗?仅当我尝试访问模块路径中的不存在页面时,它才显示空白页面.

在我的模块类中,我errorHandlerinit()函数中配置了如下组件:

public function init()   
{   
    parent::init();   
    // initialize the module with the configuration loaded from config.php   
    \Yii::configure($this, require(__DIR__ . '/config.php'));   

    \Yii::$app->setComponents([
        'errorHandler' => [
            'class' => 'yii\web\ErrorHandler',
            'errorAction' => 'studconsult/default/error',
        ] // set error action route - this to be error action in DefaultController
    ]);             
}
Run Code Online (Sandbox Code Playgroud)

在我的DefaultController班上,我的代码如下:

public function actions()   
{    
    return [    
        'error' => [    
            'class' => 'yii\web\ErrorAction',    
        ],    
    ];    
}
Run Code Online (Sandbox Code Playgroud)

error-handling custom-error-pages yii2

2
推荐指数
1
解决办法
5786
查看次数

标签 统计

custom-error-pages ×1

error-handling ×1

yii2 ×1