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

yii2模块的独立配置不生效

WBOY
WBOYOriginal
2016-06-06 20:06:511495browse

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

<code class="php">  parent::init();
  Yii::configure($this, [
    'components'=>[
        'errorHandler' => [
            'class'=>'app\modules\v1\common\ErrorHandler'
        ]
    ]
  ]);</code>

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

<code class="php">  'errorHandler' => [
      'class'=>'app\modules\v1\common\ErrorHandler'
  ]</code>

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

回复内容:

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

<code class="php">  parent::init();
  Yii::configure($this, [
    'components'=>[
        'errorHandler' => [
            'class'=>'app\modules\v1\common\ErrorHandler'
        ]
    ]
  ]);</code>

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

<code class="php">  'errorHandler' => [
      'class'=>'app\modules\v1\common\ErrorHandler'
  ]</code>

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

v1模块的init改成

<code class="php">parent::init();
Yii::$app->errorHandler->errorAction = 'app\modules\v1\common\ErrorHandler';</code>

试试看

Statement:
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