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.