I am using CDbAuthManager, and I was wondering if there was a quick way to find out the "role name" the user is assigned to.
I know I could query the database manually etc, but is there a way built in way in Yii? Something like.
Yii::app()->user->assignedRole // for current logged in user
User::model->findByPK($id)->assignedRole // for not logged in user.
Ideally I need it for both logged in and not logged in (or ANY user).
You may want to try
For more details, please see the documentation on Authentication and Authorization.
Anyone know how do this for different users? Not nessacarily the logged in user without having to query the DB manually to get the role name.
Mind you I could always just write the query once in the user model and wrap it in a method, that would not be too difficult. However still open to ideas everyone.
If you use the yii right extension, you just need create a function called getUserRoles() in the class RWebUser that extends from CWebUser, this class is under the path:
this is the code of the function:
* Retunr an array with the roles
$roles = array();
$Rol = Authassignment::model()->findAll($criteria);
$indexArray = 0;
foreach ($Rol as $item)
$roles[$indexArray] = $item->itemname;
this will return an array with the roles of the current user.