Yii Framework Forum: Access Rules defined in base controller - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

Access Rules defined in base controller Rate Topic: -----

#1 User is offline   YiiDevs 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 02-January 12

Posted 01 May 2012 - 06:21 AM

Hi,

I have an accessRules which validates for access Rights for each user using the following syntax defined in the method of each controller. Now i have many controllers, so i have to define this expression( 'expression' => 'Yii::app()->controller->isValidAccess()',) in every controller inorder to place access restriction for all the actions.

Is there any ways i can define this expression in base controller i.e (components/controller.php), so that i dont have to paste this expression in all my controllers.

Note: 'Yii::app()->controller->isValidAccess()' ---- exists in components/controller.php


/* expression defined in all my controllers */
public function accessRules() {
return array(
array('allow', // allow all users to perform 'index' and 'view' actions
'actions' => array('update','admin','create'),
//'users' => array('@'),
'expression' => 'Yii::app()->controller->isValidAccess()',
),

);
}
0

#2 User is offline   PeRoChAk 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 582
  • Joined: 26-November 10
  • Location:Lahore, Pakistan

Posted 01 May 2012 - 06:45 AM

Hi,

As Your each controller extens from CController, so if you define anything there in CContoller can be accessed and works fine for all of your controllers.

So, you need to simply place the code in base controller.

Thanks
Cheers
Perochak
Web Design - Logo Design - Application Development

My Blog | Forums Comparison
0

#3 User is offline   YiiDevs 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 02-January 12

Posted 01 May 2012 - 06:58 AM

Hi,

Thanks for the quick help, sorry but i cant define the accessRules() in a base controller, as i have different set of actions defined in my own controller,

I just need my expression in accessRules() ie('expression' => 'Yii::app()->controller->isValidAccess()',) to be placed on the base controller , so that i dont have to include this expression in all my controller for accessRules().

Many Thanks
0

#4 User is offline   PeRoChAk 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 582
  • Joined: 26-November 10
  • Location:Lahore, Pakistan

Posted 01 May 2012 - 07:06 AM

First,

You need to extend base controller first and then put access control code there and after that extend all of your controllers which you want to have these rules.

Thanks
Cheers
Perochak
Web Design - Logo Design - Application Development

My Blog | Forums Comparison
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

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