Module.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace backendApi\modules\v1;
  3. /**
  4. * Created by PhpStorm.
  5. * User: leo
  6. * Date: 2018/2/24
  7. * Time: 上午11:41
  8. */
  9. class Module extends \yii\base\Module
  10. {
  11. public $controllerNamespace = 'backendApi\modules\v1\controllers';
  12. public function init()
  13. {
  14. parent::init();
  15. \Yii::$app->user->enableSession = false;
  16. }
  17. public function behaviors()
  18. {
  19. $behaviors = parent::behaviors();
  20. $module = $this->id;
  21. $controller = $this->module->controller->id;
  22. $action = $this->module->controller->action->id;
  23. $noCheckActions = \Yii::$app->params['noCheckTokenActions'];
  24. if(!in_array($module.'/'.$controller.'/'.$action, $noCheckActions)){
  25. $behaviors['authenticator'] = [
  26. 'class' => 'yii\filters\auth\CompositeAuth',
  27. 'authMethods' => [
  28. 'yii\filters\auth\HttpBasicAuth',
  29. 'yii\filters\auth\HttpBearerAuth',
  30. 'yii\filters\auth\QueryParamAuth',
  31. ],
  32. ];
  33. }
  34. return $behaviors;
  35. }
  36. }