| 12345678910111213141516171819202122232425262728293031323334 |
- <?php
- /**
- * Created by PhpStorm.
- * User: chenkuan
- * Date: 2017/12/19
- * Time: 下午5:27
- */
- namespace wechat\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;
- }
- }
- }
|