Check role

Hi i am testing is some user has some role like this:

(example:tet if the user with the id=2 has the role admin)


$test=Yii::app()->user->checkAccess('Admin',2);

But for any value for the second parameter(user id) the test variable is always true

I’ve never used this method, but it says in the documentation that the second argument needs to be an array:

http://www.yiiframework.com/doc/api/1.1/CWebUser#checkAccess-detail

So maybe it has to be something like:


 $test=Yii::app()->user->checkAccess('Admin', array('user_id' => 2));

No.It returns always true

Isn’t


Yii::app()->user

current user? I mean … maybe


Yii::app()->user->('Admin'); 

always return true and second parameters could be used with another kind of call of checkAccess. So, it return true also when you are not logged in as Admin?

I assume you’re looking for this:




Yii::app()->authManager->checkAccess($roleName, $userId)



We can check permission or role of user by

if(Yii::app()->user->checkAccess(‘role’),Yii::app()->user->id);

or

if(Yii::app()->authManager->checkAccess(‘role’),Yii::app()->user->id);

thank you it worked

Role Based Access Control (RBAC) with Yii Framework