I have to check if user is logged before rendering every page example:
http://mypage.com/site/about
at begining check if user is logged in, if not - redirect tom login page I don't want to add it in every single componene, how to to this?
You can also check using this if it is true then user is not logged in else logged in
if(Yii::app()->user->isGuest){
//not logged user
}else{
//loggedin user
}
Use access rule to achevie this would be a better way:
public function accessRules()
{
return array(
array('allow', // allow all users to perform 'index' and 'contact' actions
'actions'=>array('index','contact'),
'users'=>array('*'),
),
array('allow', // allow authenticated user to perform 'delete' and 'update' actions
'actions'=>array('update','delete'),
'users'=>array('@'),
),
array('deny', // deny all users
'users'=>array('*'),
),
);
}
if you really want one-place checking,,then go to component/controller
and do it in the controller. because all controller inherits from that controller.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With