zipzapduo
(Zipzapduo)
July 31, 2012, 9:47pm
1
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));
zipzapduo
(Zipzapduo)
July 31, 2012, 10:33pm
3
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?
Keith
(Kburton)
August 1, 2012, 8:17am
5
I assume you’re looking for this:
Yii::app()->authManager->checkAccess($roleName, $userId)
22francis
(Jesusloves Francis)
August 1, 2012, 10:50am
6
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);
shibly27
(Shibly27)
August 1, 2012, 4:47pm
8
Role Based Access Control (RBAC) with Yii Framework