Yii::app()->User->Checkaccess()) Not Working

I have created the tables AuthItem,AuthAssignment and AuthItemChild and assigned roles as given in the yii rbac tutorials.

In my test controller when im using the following code it is giving me undefined constant.


public function actionIndex()











Here when the user who is admin logs in, i get to know that he is admin through Yii::app()->user->role but i am getting an error in the following line:


Error: Use of undefined constant ‘createProfile’ - assumed "createProfile"

Error in stack trace:

Use of undefined constant ‘createProfile’ - assumed



Stack trace:
















#5 /home/chirag/workspace/projects/drkonnect/drkonnect/web/index.php(13):






in /home/chirag/workspace/projects/drkonnect/drkonnect/web/index.php (13)

thanks in advance…!!!

You are using wrong characters as single quotes. Did you copy the code from some web page? It must have rendered them differently.

See the difference in syntax highlight:

// wrong


// right


Thankyou for pointing out the mistake…Its working now…!!

I would like to ask one more thing,

On top of my hierarchy,I have admin and i am logging as admin but in case of createProfile operation its returning me false.

Basically doctor can perform createProfile operation and admin is above doctor, so it should return true in his case.??

put a condition in or part


Thank you so much…

I want to clarify my doubt that CWebUser class has function: checkAccess($operation,$params=array(),$allowCaching=true), here its taking $operation as its parameters and in the above condition we are passing ‘Admin’ which is a role.

I am little confused about it… ???

I took me quite long time to get how RBAC works. I like to use this example:

        some profile (role)

      /     |        |      \

  read own  |    update own  delete own (operators, a set for each model)

    /       |        |        \

  read    create   update   delete (operators, a set for each model)

   \        |        |        /

    \       |        |       /

        can do something (operator)

Now when you call checkAccess() on any of this auth item it traverses the tree upwards. When any auth item got a bizrule, it is evaluated and if it’s false checkAccess() stops following that branch.

When any item is assigned to a user, checkAccess() returns true.

Auth items should be connected in such way that more restrictive items are higher in the tree.

When assigning items to roles always try to choose the highest possible item (start with least amount of privileges).

When calling checkAccess() always try to choose the lowest possible item to avoid having multiple checkAccess() calls.

This is bad:

if (Yii::app()->user->checkAccess('read Model') || Yii::app()->user->checkAccess('read own Model'))

This is better:

if (Yii::app()->user->checkAccess('read Model'))

If you would assign ‘read own Model’ to a profile checking for ‘read Model’ will pass.

Now if you want an ‘Admin’ role, just assign all elements to it.

Thanks a lot…!!!

This helped me clear me doubts… :)