【发布时间】:2014-04-06 13:36:34
【问题描述】:
我正在尝试了解 rbac 中的授权,但对一些事情感到有些困惑。
在 accessControl 规则中,我使用了这样的角色:
return array(
array('allow', // allow all users to perform 'index' and 'view' actions
'actions'=>array('index', 'view'),
'roles'=>array('user'),
),
array('allow', // allow authenticated user to perform 'create' and 'update' actions
'actions'=>array('create','update'),
'roles'=>array('author'),
),
array('allow', // allow admin user to perform 'admin' and 'delete' actions
'actions'=>array('admin','delete'),
'roles'=>array('admin'),
),
array('deny', // deny all users
'users'=>array('*'),
),
);
我也在使用以下设置:
$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('user');
$role->addChild('readPost');
$role = $auth->createRole('author');
$role->addChild('user');
$role->addChild('createPost');
$role = $auth->createRole('admin');
$role->addChild('author');
$role->addChild('updatePost');
$role->addChild('deletePost');
$auth->assign('user', 3);
$auth->assign('author', 2);
$auth->assign('admin', 1);
$auth->save();
有 4 种不同的操作名称(createPost、deletePost、readPost、udpatePost)。但是在控制器中,动作名称是不同的,例如 actionIndex、actionView、actionCreate、actionDelete、actionUpdate 和 actionAdmin。
问题:
如何将操作映射到控制器操作。
是否应该创建更多操作,例如 IndexPost、ViewPost 等?
在使用 rbac 时,我们是否仍应像我在这里所做的那样保留访问控制过滤器和规则?
我不确定我是否做得对。很多困惑和迷失。请阐明一些观点。干杯。
【问题讨论】:
标签: yii