checkAccess failure


I’ve honestly exhausted a search on a possible explanation for this before posting, so please your help will be appreciated.

I’m trying something as simple as using checkAccess to see if user is admin however I’m not getting any results…I’m stumped. I’m accessing it in a view file, where the objective is to show a specific link for admins (and in the future, I will have respective links of other users/user groups).

My question is why isn’t " Yii::app()->user->checkAccess(‘admin’) " working when the user is logged in as admin?

am I lacking the required braincells to figure this out lol please help?

<?php if (Yii::app()->user->checkAccess('admin')) {

    $this->widget('zii.widgets.CMenu', array(

        'items' => $this->menu,

        'htmlOptions' => array('class' => 'operations'),


} else { echo "<small>Please login</small>";}


When using Yii::app()->user->checkAccess(‘admin’) like this, you have to implement all the Role-Based Access Control. See Topics Auth

Otherwise you have to use:

  if (Yii::app()->user->id == 'admin') 


check this wiki I wrote a couple days ago

Thanks for the quick replies.

Joblo: your suggestion worked perfectly, and in the mean time I will learn more about RBAC

Gustave : thanks, very useful functions :)


Hello Joblo,

In my AuthItem table i have 3 enteries

1: name->admin, type->2, description->admin, bizrull->null, data->N;

2: name->authotized, type->2, description->logedin, bizrull->return !Yii::app()->user->isGuest;, data->N;

3: name->guset, type->2, description->guest, bizrull->return Yii::app()->user->isGuest;, data->N;

In AuthAssignment i have one entry:

1: useritem:admin,userid=22,bizrull=null,data=N;

Below is the UserIdentity code:

public function authenticate()





	else if(md5(&#036;record-&gt;password)&#33;==md5(&#036;this-&gt;password))







	return &#33;&#036;this-&gt;errorCode;


Below is the code in userController:

public function accessRules()


	return array(

		array('allow',  // allow all users to perform 'index' and 'view' actions




		array('allow', // allow authenticated user to perform 'create' and 'update' actions




		array('allow', // allow admin user to perform 'admin' and 'delete' actions




		array('deny',  // deny all users





Login works perfectly… access works correctly

I wants to hide create and admin link from all other users. I am trying below code and it is not working:

//if(Yii::app()->user->id==‘admin’){ //works well

if(Yii::app()->user->checkAccess(‘admin’)){//dont work


	array('label'=&gt;'Create User', 'url'=&gt;array('create')),

	array('label'=&gt;'Manage User', 'url'=&gt;array('admin')),



Pl help what i an doing wrong