Yii Framework Forum: Need Help to checking Permission - Yii Framework Forum

Jump to content

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

Need Help to checking Permission Rate Topic: -----

#1 User is offline   Dan Din Dun 

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

Posted 01 March 2010 - 09:10 PM

Hi.
I have a class that extended from Controller.
here is the class

the class name is Controller.php that located in protected/components/
class Controller extends CController
{
	/**
	 * @var array the breadcrumbs of the current page. The value of this property will
	 * be assigned to {@link CBreadcrumbs::links}. Please refer to {@link CBreadcrumbs::links}
	 * for more details on how to specify this property.
	 */
	public $breadcrumbs=array();

        public function init(){
            parent::init();
        }

        public function checkAuth(){
            if(Yii::app()->controller->action->id !== 'login'){
                if(Yii::app()->user->isGuest){
                    $this->redirect(array('admin/login'));
                }
            }
        }
}


the checkAuth() function is used to checking permission that allow only non-guest member to access the action in controller.

I have been using this way (manual way) to checking current user permission:

class SiteController extends Controller {
   public function actionAdmin(){
      $this->checkAuth();
      ...
   }

   public function actionAdd(){
      $this->checkAuth();
      ...
   }

   public function actionEdit(){
      $this->checkAuth();
      ...
   }
}


whether there is another way that is more practical to put checkAuth function(). so I no longer need to put checkAuth function() every action controller?

thanks for advance :-)
Thanks and Kind Regards
------
DanDinDun
0

#2 User is offline   andy_s 

  • Random Member Title
  • Yii
  • Group: Moderators
  • Posts: 1,526
  • Joined: 22-June 09
  • Location:Russia, Kostroma

Posted 02 March 2010 - 02:17 AM

In Controller.php rewrite this method:

http://www.yiiframew...reAction-detail

Don't forget to return true in the end of it.
0

#3 User is offline   Dan Din Dun 

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

Posted 02 March 2010 - 05:29 AM

View Postandy_s, on 02 March 2010 - 02:17 AM, said:

In Controller.php rewrite this method:

http://www.yiiframew...reAction-detail

Don't forget to return true in the end of it.


:) thank you mr. Andy_s, fixed. :)
Thanks and Kind Regards
------
DanDinDun
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