简体   繁体   中英

Yii Framework: how to set default User Roles

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM