MarBer MarBer - 4 months ago 72
PHP Question

Yii2 accessControl force redirect to lgoin whitout behaviors

I've created a small module some week ago, now I need to work with this module but when i open the module link I have got redirect to login page, the module no have behaviors defined, if i don't mistake this let full access at all user, for test I've set on main module controller this behavior

public function behaviors(){
return [
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'actions' => ['*'],
'allow' => true,
]
]
]
];
}


but the application redirect me to login page.
How i can allow access to all users?
Thanks

Answer

If you don't need access control, you should simply remove the behavior.

Or use this :

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

About AccessRule::$actions :

List of action IDs that this rule applies to. The comparison is case-sensitive. If not set or empty, it means this rule applies to all actions.

Comments