Use yii's RBAC

I am trying to use yii’s RBAC. Therefor I am following this document here.

I set up the following in the main config file:




'authManager'=>array(

            'class'=>'CPhpAuthManager',

        ),

The auth.php is writable but empty in the data folder.

I am trying to run this code without success:




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

 

$auth->createOperation('createPost','create a post');

$auth->createOperation('readPost','read a post');

$auth->createOperation('updatePost','update a post');

$auth->createOperation('deletePost','delete a post');

 

$role=$auth->createRole('reader');

$role->addChild('readPost');

 

$role=$auth->createRole('author');

$role->addChild('reader');

$role->addChild('createPost');

$role->addChild('updateOwnPost');

 

$role=$auth->createRole('editor');

$role->addChild('reader');

$role->addChild('updatePost');

 

$role=$auth->createRole('admin');

$role->addChild('editor');

$role->addChild('author');

$role->addChild('deletePost');

 

$auth->assign('reader','readerA');

$auth->assign('author','authorB');

$auth->assign('editor','editorC');

$auth->assign('admin','adminD');

I am getting this error message - presumably because my auth.php file empty?!


Invalid argument supplied for foreach()

Do I need to create roles within the auth.php file as well? It sounded like I can use $role=$auth->createRole(‘author’); instead?

Maybe I am on a completely wrong track here…

put:

$auth->save();

at the end…

Hello,

I am having the similar problem where i am using CBDAuthManager

In config/main.php

‘authManager’=>array(

		'class'=>'CDbAuthManager',


		'connectionID'=>'db',


		'defaultRoles'=>array('authenticated','guest', 'admin'), //authenticated=logged in user & admin=user name is equal to admin


	),

I am trying to run this code without success:

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

$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->name === “admin”;’;

$role = $auth->createRole(‘admin’, ‘administrator’);

$auth->assign(‘admin’,1); // adding admin to first user created

$bizRule = ‘return Yii::app()->user->id==$params[“User”]->id;’;

$auth->createTask(‘updateSelf’, ‘update own information’, $bizRule);

$role = $auth->getAuthItem(‘authenticated’); // pull up the authenticated role

$role->addChild(‘updateSelf’); // assign updateSelf tasks to authenticated users

$auth->save();

Firstly i am not sure where to put this file and how to execute. Your help would be great.

Solved: pl check http://www.yiiframework.com/forum/index.php/topic/44894-creating-authorization-roles/

is it possible somebody tell me how could i put access for my auth.php for apache?