The Question: How do I check if a user has a particular role assigned?
Context: I am new to Yii and just recently I’ve been assigned to a project using Yii.
I have setup RBAC using the Database approach and to my understanding is working correctly, all I have done is modify the accessRules and replaced ‘users’ for ‘roles’=>array(‘role1’,‘role2’).
Scenario:
I am trying to implement a check on a user assigned role to redirect the user to different view depending on the role he/she has been assigned to, but I’m not sure of what are the steps to follow.
For example:
User1 => Admin, then after login it should land on an Admin view
User2 => User, then after login it should land on a User view
The way I fixed this was to save the user role as a state in the webuser and then checking the role in the layout/main.php, this will give you alot of if statements if you have alot of roles but works for smaller websites.