Role-Based Access Control (RBAC) provides simple yet powerful centralized access control. It is the most powerful access control method available in Yii. It is described in the guide, but since it is rather complex and powerful, it is not as easy to understand without getting under the hood a little.
In this recipe, we will take the roles hierarchy from the definitive guide, import it, and explain what is happening internally.
Create a new application by using the Composer package manager, as described in the official guide at http://www.yiiframework.com/doc-2.0/guide-start-installation.html.
Create a MySQL database and configure it.
Configure the
authManager
component in yourconfig/main.php
andconfig/console.php
as follows:return [ // ... 'components' => [ 'authManager' => [ 'class' => 'yii\rbac\DbManager', ], // ... ], ];
Run the migration:
yii migrate --migrationPath=@yii/rbac/migrations