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

yii2模块的独立配置不生效

WBOY
Release: 2016-06-06 20:06:51
Original
1474 people have browsed it

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

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

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

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

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

回复内容:

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

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

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

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

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

v1模块的init改成

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

试试看

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template