Cexception Unknown Authorization Item

Hello Fellow Yii Programmers,

I am having an issue with my RBAC. I used a wiki to set it up, but it does not appear to work. When I attempt to run an action whose access is controlled by a role, the topic title is what happens. I get the error message “CException Unknown authorization item ‘customer’.”

The relevant code…

from config/main.php:




'components'=>array(

		

		'authManager'=>array(

			'class'=>'PTPhpAuthManager',

		),



my data/auth.php:




<?php


return array(

    'user'=> array(

        'type'=>CAuthItem::TYPE_ROLE,

        'description'=>'A user with no profile',

        'bizRule'=>'',

        'data'=>''

   ),

   

    'customer' => array (

        'type'=>CAuthItem::TYPE_ROLE,

        'description'=>'A customer user',

        'bizRule'=>'',

        'data'=>''

   ),

 

    'agent' => array (

        'type'=>CAuthItem::TYPE_ROLE,

        'description'=>'a member agent of the team',

        'bizRule'=>'',

        'data'=>''

    ),

 

    'admin' => array (

        'type'=>CAuthItem::TYPE_ROLE,

        'description'=>'team leader or web site admin',

        'children'=>array(

            'customer','agent'

        ),

        'bizRule'=>'',

        'data'=>''

   )

);


?>



My components/PTPhpAuthManager.php




<?php


class PTPhpAuthManager extends CPhpAuthManager

{

	public function init() {

		if($this->authFile===null) {

			$this->authFile=Yii::getPathOfAlias('application.config.auth').'.php';

		}


		parent::init();


		$this->defaultRoles = array('guest');

		if(Yii::app()->user->role=='')

			Yii::app()->user->role='user';

		if(!Yii::app()->user->isGuest) {

			$this->assign(Yii::app()->user->role, Yii::app()->user->id); <---- line where the exception occurs

		}

	}

}


?>



The access control part of a controller:




	public function accessRules()

	{

		return array(

			array('allow',  

				'actions'=>array('index','view','search'),

				'users'=>array('*'),

			),

			array('allow',

				'actions'=>array('create','update','newListing','lookup'),

				'roles'=>array('admin','agent','customer'),

			),

			array('allow', 

				'actions'=>array('admin','delete'),

				'roles'=>array('admin'),

			),

			array('deny', 

				'users'=>array('*'),

			),

		);

	}



I think that is all the relevant code. If I have left anything out, please let me know.

Thank you for your time.

Hi

I had same problem. every time i have had this problem, it was because of permission.

I am using ubuntu, my own user is rivaldo and apache user is www-data, sometimes by mistake i change owner of the file to rivaldo:rivaldo so my eclipse can change the file (i am doing it by mistake), but the right owner of this file is www-data.

to solve this problem i changed owner of this file and its parent directory(data) to www-data and it fixed this error and it started working.

chown www-data -R PARENT_DIRECTORY

I hope this helps.

I also have this problem. I tried your solution but it’s not working at all.