Hi,
I’m learning in theese days for a first time Yii Framework and I have a trouble in setting authorization.
My goal is to personalize menu based on the user’s role.
In controller file I put this simple code:
protected function loadAuth()
{
$auth=Yii::app()->authManager;
$auth->createOperation('manageUtenti','gestisci gli utenti');
$role=$auth->createRole('user');
$role->addChild('manageUtenti');
}
public function init()
{
$this->loadAuth();
}
and I notice that this execution insert in my database table authorization the correct records in AuthItem and AuthItemChild tables.
During the authentication I set the user roles in this way:
$this->setState('roles', $record->VANUT_Roles);
in the authenticate() method:
public function authenticate()
{
$record=ANUTAnagraficaUtenti::model()->findByAttributes(array('VANUT_Username'=>$this->username));
if($record===null)
$this->errorCode=self::ERROR_USERNAME_INVALID;
else if($record->VANUT_Password!==crypt($this->password,$record->VANUT_Password))
$this->errorCode=self::ERROR_PASSWORD_INVALID;
else
{
$this->_id=$record->IANUT_IdUtente;
$this->setState('roles', $record->VANUT_Roles);
$this->errorCode=self::ERROR_NONE;
}
return !$this->errorCode;
}
In my menu file I put this code:
$this->widget('zii.widgets.CMenu',array(
'htmlOptions'=>array('class'=>'pull-right nav'),
'submenuHtmlOptions'=>array('class'=>'dropdown-menu'),
'itemCssClass'=>'item-test',
'encodeLabel'=>false,
'items'=>array(
array('label'=>'Dashboard', 'url'=>array('/site/index'),'visible'=>Yii::app()->user->checkAccess('manageUtenti')), ....
But the command Yii::app()->user->checkAccess(‘manageUtenti’) return everytime FALSE. Also when the user logged have user role.
What I mistake?
Thank in advance for your help!
Have a nice day,
Domenico