Disable CSRF validation for individual actions in Yii2

前端 未结 4 1633
北恋
北恋 2020-11-27 16:52

Is there a way to disable CSRF validation for some actions of the controller keeping it enabled for the other ones?

In my case I have several configurable Action cla

4条回答
  •  鱼传尺愫
    2020-11-27 17:17

    For me this is what worked

    public function beforeAction($action) {
        if($action->id == 'my-action') {
            Yii::$app->request->enableCsrfValidation = false;
        }
        return parent::beforeAction($action);
    }
    

提交回复
热议问题