Dear All,
I have trid to implementing ACL using CDBAuthManager, I have created 3 table using schema in "framework/web/auth/schema.sql" and successfull.
I have tried to
Yii::app()->authManager->createRole('admin');
it works too.
but I don’t know how to use this correctly and according to which has been defined by yii.
can anyone making for us an example to use it? please…
thanks.
ibnusarnan
(Didienna)
February 13, 2010, 11:16pm
2
Dear All,
I have trid to implementing ACL using CDBAuthManager, I have created 3 table using schema in "framework/web/auth/schema.sql" and successfull.
I have tried to
Yii::app()->authManager->createRole('admin');
it works too.
but I don’t know how to use this correctly and according to which has been defined by yii.
can anyone making for us an example to use it? please…
thanks.
I try to implement it in actionCreate
public function actionCreate(){
if(Yii::app()->authManager->checkAccess('create',Yii::app()->user->getId())){
$model = new Users;
$model->action = 'create';
$data['model'] = $model;
$data['action'] = array('users/create_process');
$this->render('create',$data);
}else{
Yii::app()->user->setFlash('error','You don not have permission');
$this->redirect(array('users/admin'));
}
}
but I doubt this way. having to add every action.
perhaps there is a more efficient way than this? please…
thanks
dcolley
(Derek)
February 15, 2010, 6:50pm
3
Have a look at framework/web/auth/schema.sql for the required table structures.
Populate the tables according to the RBAC documentation in the documents and forums.
http://www.yiiframework.com/doc/cookbook/65/
http://www.yiiframework.com/forum/index.php?/topic/2313-rbac-confusion
http://www.yiiframework.com/doc/guide/topics.auth#c1113
Include this in your BlahController.php
public function accessRules() {
return array(
array('allow',
'actions'=>array('list'),
'roles'=>array('blahList'),
),
array('allow',
'actions'=>array('create'),
'roles'=>array('blahCreate'),
),
array('allow',
'actions'=>array('view','show'),
'roles'=>array('blahView'),
),
array('allow',
'actions'=>array('edit','update'),
'roles'=>array('blahEdit'),
),
array('allow',
'actions'=>array('delete'),
'roles'=>array('blahDelete'),
),
array('allow',
'actions'=>array('admin'),
'roles'=>array('blahAdmin'),
),
array('deny', // deny all users
'users'=>array('*'),
),
);
}