a question with authManager()

I used RBAC for my website!

But I don’t know how to use saveAuthItem()~~~

Could you give me a example about use saveAuthItem()~~~?TKS~

BTW~~~ bizrule what it meaning~~~ :lol:

// create initial authorization roles

$auth = Yii::app()->authManager;

if (!$auth) {

    echo "No AuthManager is defined.\n";

    return false;


$auth->createOperation('createCompany', 'Create a new company record');

$auth->createOperation('readCompany', 'View company records');

// example of a task.

$bizRule = 'return Yii::app()->user->id == $params["company"]->last_updated_user_id;';

$task = $auth->createTask('updateOwnCompany', 'Update a company record owned by a user', $bizRule);

$role = $auth->createRole('dataReader', 'Read all public data');



$role = $auth->createRole('dataCreator', 'Create all public data');


$role = $auth->createRole('dataAdmin', 'Administer all public data');



// assign out initial roles and permissions

$userNames = array('tom', 'dick', 'harry');

foreach ($userNames as $name) {

    $user = User::model()->findByAttributes(array('name' => $name));

    if ($user) {

        $auth->assign('dataAdmin', $user->id);



Bhank you Preston Brown ~~~

But I don’t see how to edit the name or the description of the role or the Operation!


You mean after it is already created?

How about:

$role = $auth->getAuthItem('dataCreator');

$role->name = 'dataMaker';

$role->description = 'Make Data!';

$auth->saveAuthItem($role, 'dataCreator'); // have to give the old name so the auth manager can fix all relations

yes~it is~~


Thank you very much~~~~~~