parent::init(); yii::configure($this, [ 'components'=>[ 'errorhandler' => [ 'class'=>'app\modules\v1\common\errorhandler' ] ] ]);
然后我在控制器中加了一行throw new httpexception(403);
最后控制器中怎么没走到我自定义的errorhandle里面呢?
可是我在项目中的config/web.php的components中加入
'errorhandler' => [ 'class'=>'app\modules\v1\common\errorhandler' ]
就能够正常走自定义的errorhandler,这是为什么呢?
回复内容: 我项目中有一v1模块,在v1.php中的init代码中加载了配置
parent::init(); yii::configure($this, [ 'components'=>[ 'errorhandler' => [ 'class'=>'app\modules\v1\common\errorhandler' ] ] ]);
然后我在控制器中加了一行throw new httpexception(403);
最后控制器中怎么没走到我自定义的errorhandle里面呢?
可是我在项目中的config/web.php的components中加入
'errorhandler' => [ 'class'=>'app\modules\v1\common\errorhandler' ]
就能够正常走自定义的errorhandler,这是为什么呢?
v1模块的init改成
parent::init();yii::$app->errorhandler->erroraction = 'app\modules\v1\common\errorhandler';
试试看