Home > Backend Development > PHP Tutorial > yii2模块的独立配置不生效

yii2模块的独立配置不生效

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:06:51
Original
1516 people have browsed it

我项目中有一v1模块,在V1.php中的init代码中加载了配置

  parent::init();
  Yii::configure($this, [
    'components'=>[
        'errorHandler' => [
            'class'=>'app\modules\v1\common\ErrorHandler'
        ]
    ]
  ]);
Copy after login
Copy after login

然后我在控制器中加了一行throw new HttpException(403);
最后控制器中怎么没走到我自定义的errorhandle里面呢?
可是我在项目中的config/web.php的components中加入

  'errorHandler' => [
      'class'=>'app\modules\v1\common\ErrorHandler'
  ]
Copy after login
Copy after login

就能够正常走自定义的errorHandler,这是为什么呢?

回复内容:

我项目中有一v1模块,在V1.php中的init代码中加载了配置

  parent::init();
  Yii::configure($this, [
    'components'=>[
        'errorHandler' => [
            'class'=>'app\modules\v1\common\ErrorHandler'
        ]
    ]
  ]);
Copy after login
Copy after login

然后我在控制器中加了一行throw new HttpException(403);
最后控制器中怎么没走到我自定义的errorhandle里面呢?
可是我在项目中的config/web.php的components中加入

  'errorHandler' => [
      'class'=>'app\modules\v1\common\ErrorHandler'
  ]
Copy after login
Copy after login

就能够正常走自定义的errorHandler,这是为什么呢?

v1模块的init改成

parent::init();
Yii::$app->errorHandler->errorAction = 'app\modules\v1\common\ErrorHandler';
Copy after login

试试看

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
yii2 error connecting to mongodb3.2.4
From 1970-01-01 08:00:00
0
0
0
How to use mongodb to do rbac in yii2
From 1970-01-01 08:00:00
0
0
0
php - yii2-ueditor-widget
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template