I’ve read Yii’s documentation about “role-based-access-control” but I didn’t found where to configure default user roles.
I’ve add:
'authManager'=>array(
'class'=>'CDbAuthManager',
'connectionID'=>'db',
'defaultRoles'=>array('guest', 'authenticated', 'admin'),
),
to protected/config/main.php
But where I have to put these business rules?
$bizRule='return !Yii::app()->user->isGuest;';
$auth->createRole('authenticated', 'authenticated user', $bizRule);
$bizRule='return Yii::app()->user->isGuest;';
$auth->createRole('guest', 'guest user', $bizRule);
$bizRule='return Yii::app()->user->admin;';
$auth->createRole('admin', 'admin user', $bizRule);
Thanks for any help!
Doing this via the code you started will be a pain. Instead use the Rights extension which was created for this job.
Rights extension utilizes Yii’s built-in Database Authorization Manager (CDbAuthManager) to provide a web interface for advanced access control.