rbac

Hi All!

I red already the posts concerning RBAC, they didn’t help me…

i put the auth.php in protected/commands/shell/auth.php…

then how to run the yiic rbac,

am also put rbac folder in protected/modules how to run that one,

am send here sample code of auth.php




<?php





class RbacCommand extends CConsoleCommand


{


    public function run($args)


    {


      $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');





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


$task=$auth->createTask('updateOwnPost','update a post by author himself',$bizRule);


$task->addChild('updatePost');





$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('admin','demo');





$auth->save(); 


    }


}








?>



This script will just store auth data into db(in few tables), so check first if records are saved correctly.

Next thing is that you need to check access to particular task/operation using command:


Yii::app()->user->checkAccess('createPost')

You can use this command both in controllers and views(for example to show/hide menu link, depending on user role).

commands should be in protected/commands, and you said yours is in protected/modules

after its in the right folder, just execute the command




yiic rbac

if you already doesn’t do that, you should also check if its a command or a web request, check this post

and you are done

thanking for giving reply

hi

In the command prompt i am entering in the following

D:\dev\Apache\htdocs>seven\protected\commands\auth.php

am getting invalid directory …what will do,please help me

Remove greater than symbol from in between of htdocs>seven

Try this:




  "D:\dev\Apache\htdocs\seven\protected\commands\auth.php"