Answer the question
In order to leave comments, you need to log in
How does Rbac work in Yii2?
Such a question, for example, is the role of the author, the author can add a record and edit his records, there is an admin role, the admin can add records and edit all records.
Code example:
$auth = Yii::$app->authManager;
$createPost = $auth->createPermission('createPost');
$updatePost = $auth->createPermission('updatePost');
$updateOwnPost = new UpdateOwnPostRule();
$auth->add($createPost);
$auth->add($updatePost);
$auth->add($updateOwnPost);
$auth->addChild($updateOwnPost, $updatePost);
$author = $auth->createRole('author');
$admin = $auth->createRole('admin');
$auth->add($author);
$auth->add($admin);
$auth->addChild($author, $createPost);
$auth->addChild($author, $updateOwnPost);
$auth->addChild($admin, $author);
$auth->addChild($admin, $updatePost);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question