Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. public function behaviors()
  2. {
  3. $behaviors = parent::behaviors();
  4.  
  5. $auth = $behaviors['authenticator'] = [
  6. 'class' => HttpBearerAuth::className(),
  7. 'only' => ['can-access'],
  8. ];
  9. $behaviors['access'] = [ //This fails
  10. 'class' => AccessControl::className(),
  11. 'only' => ['can-access'],
  12. 'rules' => [
  13. [
  14. 'actions' => ['can-access'],
  15. 'allow' => true,
  16. 'roles' => ['@'],
  17. ],
  18. ],
  19. ];
  20. $behaviors['contentNegotiator'] = [
  21. 'class' => ContentNegotiator::className(),
  22. 'formats' => [
  23. 'application/json' => Response::FORMAT_JSON,
  24. ],
  25. ];
  26.  
  27. ];
  28.  
  29.  
  30. $behaviors['authenticator']['except'] = ['options'];
  31. return $behaviors;
  32. }
  33.  
  34. public function actionCanAccess()
  35. {
  36. echo $access = Yii::$app->user->isGuest; //this returns false
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement