Disable CSRF validation for individual actions in Yii2

前端 未结 4 1627
北恋
北恋 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 16:59

    Put this inside your controller, just replace index with whatever action you want to disable csrf on.

    public function beforeAction()
    {      
        if ($this->action->id == 'index') {
            $this->enableCsrfValidation = false;
        }
        return true;
    }
    

提交回复
热议问题