Answer the question
In order to leave comments, you need to log in
How to create RBAC role using migrations in yii?
Hello!
To create a role, use the following code:
$role = Yii::$app->authManager->createRole('admin');
$role->description = 'Администратор';
Yii::$app->authManager->add($role);
public function safeUp()
{
$this->insert('auth_item',[
'name' => 'admin',
'type' => 1,
'descryption' => 'Administrator',
]);
}
Answer the question
In order to leave comments, you need to log in
You must create roles in migrations in the same way as you do in the first way - through authManager. Here in the docks . To do this, check that this component is present in the console config
It would be nice to point out the error you are seeing. But I'll assume...
To start with, check whether "authManager" is configured in the console to add a role through it.
Check if the role was created earlier...
That 's the idea to do it right...
But in the case when we have permission added during the development of the project, this option can become a headache, since each time you will need to reset the permissions in order to added new...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question