我項目中有一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模組,在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';
試試看