Yii Framework Forum: Need help implementing ACL using database - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Need help implementing ACL using database Rate Topic: -----

#1 User is offline   Dan Din Dun 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 77
  • Joined: 09-February 10

Posted 13 February 2010 - 11:16 AM

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.
Thanks and Kind Regards
------
DanDinDun
0

#2 User is offline   Dan Din Dun 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 77
  • Joined: 09-February 10

Posted 13 February 2010 - 06:16 PM

View PostDan Din Dun, on 13 February 2010 - 11:16 AM, said:

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
Thanks and Kind Regards
------
DanDinDun
0

#3 User is offline   DerekC 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 44
  • Joined: 09-December 09
  • Location:Europe

Posted 15 February 2010 - 01:50 PM

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.yiiframew...oc/cookbook/65/
http://www.yiiframew...-rbac-confusion
http://www.yiiframew...pics.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('*'),
			),
		);
	}

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users