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…