Friday, December 5, 2014

Yii User access rules

Standard



this for YII USER MODULE
Load and store the user's data every time a page is requested. To do this, modify the Controller class as follows:
i added this on  compound controller becouse  All controller classes for this application should extend from this base class.





          public function isGuest() {
            $user=User::model()->active()->findbyPk(Yii::app()->user->id);
//            print_r($user->superuser);
            if($user->superuser==0)
            {throw new CHttpException(403, 'You have no permission to view this content');}
           
            return UserModule::isAdmin();
        }

add this expression for all accessRules

 public function accessRules()
 {
            return array(

            array('allow', // allow admin user to perform 'admin' and 'delete' actions
                        'actions'=>array('index','view','delete', 'admin'),
                        'expression'=> $this->isAdmin(),
                        ),
                       
            );
 }



0 comments:

Post a Comment