How I can give RBAC to user, depends on his database 'role' data?

I write this lines into the config file:




 'authManager' => [

            'class' => 'yii\rbac\PhpManager',

            'authFile' => '@app/config/rbac.php'

        ],



In rbac.php I wrote roles, for example one admin role here:




<?php


return array (

    'items' =>array(

        'admin'=>array (

            'type'=>1, //Where I can read about this types? What this 1 means?

            'name'=>'admin',

            'ruleName' => 'admin'

        )

    )

);



After it it start to be difficult for realising. How I can give to user admin, if his database ‘role’ data is ‘admin’? I want after it work with this in views and controllers with this code:




if (Yii::$app->user->can('admin')) {

     //do something, which can do admin only

}



I read documentation, but can’t understand how to do it. I have got few questions as well:

  1. How to give role to a user? I can take data from db to variable $role. And what I must to do after it?



if ($role == 'admin') {

     //give this user admin role. How I can do that?

}



  1. Where and when I can do that? I don’t want to do it every time, I can create something automatic mode of it.

So, do you recomend best solution of advanced role realisation with database data?