How to implement two or more identity Class in yii2?


(Jamess) #1

I am using Yii2 basic.

I have Employee table and I have assigned Employee model to user application component as follows in config file:

‘user’ => [

        'identityClass' => 'app\models\Employee',


        'enableSession' => true,


      ],

Now the scenario is there is one main admin who can access everything including Employee, Employee Training CRUD’S and admin can assign roles to created employees and then employees can login and they should only be able to access their own Profile, SHGProfile CRUD, etc.

There should be two tables Employee and Admin.

How can we implement this using two identity classes, one for Employee stated above and other for admin?


(Cleippi) #2

You might be interested in looking into RBAC. No need for two separate user tables.


(Rafał Rudowski) #3

For this is simple solution:
https://www.yiiframework.com/wiki/864/how-to-login-from-different-tables-in-yii2?revision=7