<?php
/**
 * Created by PhpStorm.
 * User: chenkuan
 * Date: 2017/12/19
 * Time: 下午5:27
 */

namespace frontend\models\behaviors;


use yii\base\ActionEvent;
use yii\base\Behavior;
use yii\web\Controller;

class NoCSRFBehavior extends Behavior
{
    /** @var ActionEvent */
    public $actions = [];
    public $controller;

    public function events()
    {
        return [Controller::EVENT_BEFORE_ACTION => 'beforeAction'];
    }

    public function beforeAction($event)
    {
        $action = $event->action->id;
        if (in_array($action, $this->actions)) {
            $this->controller->enableCsrfValidation = false;
        }
    }
}
