Answer the question
In order to leave comments, you need to log in
Yii2 - RBAC. Default Roles and Access Control. Doesn't work as it should?
The problem is that AccessControl does not work the same way for standard user groups ('?' and '@') and those defined via PhpManager
Here are the roles defined in the rbac.php file ($authFile)
3 => [
'type' => Item::TYPE_ROLE,
'description' => 'Гость',
],
2 => [
'type' => Item::TYPE_ROLE,
'description' => 'Пользователь',
'ruleName' => 'UserRule',
'children' => [
3,
],
],
1 => [
'type' => Item::TYPE_ROLE,
'description' => 'Админ',
'ruleName' => 'AdminRule',
'children' => [
2,
],
],
'authManager' => [
'class' => 'common\components\rbac\PhpManager',
'defaultRoles' => [1,2,3],
],
'access' => [
'class' => AccessControl::className(),
'only' => ['logout', 'signup','test'],
'rules' => [
[
'actions' => ['test'],
'allow' => true,
'roles' => [2], // Разрешить только для пользователей с ролью "2".
],
],
],
'denyCallback' => function (){throw new ForbiddenHttpException(Yii::t('yii', 'Login Required'));}
Answer the question
In order to leave comments, you need to log in
the code is not enough to solve the problem, and apparently you modified the component.
I advise you to use this https://github.com/zelenin/yii2-rbac-module
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question