Customization Yii2 RBAC system for another table user

Hi coders,

i have problem with customize Yii2 RBAC.
I have 2 different user…

  1. user table specialist for student, lecturer
  2. admin table specialist for admin only…

i have no problem with user table (rbac)… the problem is how to i do rbac using admin table… if i did, always use rbac user table…

please help me … i dont know how to solve it

Hi @mazfreelance;

Welcome back to community;

In your model extended from IdentityInterface try using this method

/**
 * @inheritdoc
 */
public static function tableName()
{
    return 'TABLENAME;
 }

thank you for helping… btw , i already implement what you said earlier … the problem is yii\web\User:_access … that function just show user access on user table … not admin table (custom users for role admin)

yii\web\User#1
(
    [identityClass] => 'backend\\models\\BackendUsers'
    [enableAutoLogin] => true
    [enableSession] => true
    [loginUrl] => [
        0 => 'site/login'
    ]
    [identityCookie] => [
        'name' => '_identity-backend'
        'httpOnly' => true
    ]
    [authTimeout] => 1800
    [accessChecker] => null
    [absoluteAuthTimeout] => null
    [autoRenewCookie] => true
    [idParam] => '__id'
    [authTimeoutParam] => '__expire'
    [absoluteAuthTimeoutParam] => '__absoluteExpire'
    [returnUrlParam] => '__returnUrl'
    [acceptableRedirectTypes] => [
        0 => 'text/html'
        1 => 'application/xhtml+xml'
    ]
    [yii\web\User:_access] => [
       '/site/index' => false
       '/site/*' => false
       '/*' => true
    ]
    [yii\web\User:_identity] => backend\models\BackendUsers#2
    (
        [yii\db\BaseActiveRecord:_attributes] => [
            'id' => 1
            'username' => 'test@email.com
            'auth_key' => 'aTPrpDA9LgOkHgZZLXND7FgBmPvyHTS7'
            'password_hash' => '$2y$13$JoYO0snthenbOL87wYKp2eZfvc.s4WT6fVNd9PuLY9Nb0rh2FYKni'
            'phone' => ''
            'role_type' => 'Admin'
            'publisher_id' => 1
            'status' => 1
            'created_at' => '2019-07-02 17:47:03'
            'updated_at' => '2019-07-03 12:01:25'
        ]

You should use one table for all users, and use rbac for managing user rights. This approach you follow I think is problematic from its beginning. Nevertheless, if you still want to use your approach, you could separate the logins from the start, each of them create a different user with different model looking in different tables, user, admin