Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Allow everyone to access in Yii2 controller

Tags:

yii

yii2

I have a project where I am implementing an existing Yii project on top. The issue is the new Yii project has its own user login and authentication. I want to allow anyone access by global rights or just remove all of the authentication all together and use my own page authentication.

In my site controller I have modified to:

public function behaviors()
{
    return [
       'access' => [
           'class' => AccessControl::className(),
           'rules' => [
               [
                   'allow' => true,
                   'roles' => ['?'],
               ],
               // ...
           ],
       ],
    ];
}

I have removed the actionLogin() and actionLogout() from this site controller as well but am still sent to the logon page.

  • *: any user, including both anonymous and authenticated users.
  • ?: anonymous users.
  • @: authenticated users.

This is what I have added: https://github.com/gugoan/economizzer

public function behaviors()
    {
      return [
        'access' => [
            'class' => AccessControl::classname(),
            'only'  => ['index','create','update','delete','view','target','accomplishment','overview','performance'],
            'rules' => [
                [
                    'allow' => true,
                    'roles' => ['*']
                ],
            ]
        ],
        'verbs' => [
            'class' => VerbFilter::className(),
            'actions' => [
                'delete' => ['post'],
            ],
        ],
    ];
   }
like image 877
user1956040 Avatar asked Sep 16 '25 06:09

user1956040


1 Answers

There is no role *, you need to use:

'roles' => ['?', '@']
like image 170
rastik Avatar answered Sep 19 '25 15:09

rastik