I have made a file applicationBehavior.php
which are in the component folder, like this :
<?php
class applicationBehavior extends CBehavior
{
public function events()
{
return array(
'onBeginRequest'=>'massLogout',
);
}
public function massLogout()
{
$owner = $this->getOwner();
if($owner->getGlobalState('massLogout') && ($owner->user->name!=='bertho'))
{
$owner->user->clearStates();
$owner->catchAllRequest=array('maintenance','view'=>'index');
}
}
}
And I have already registered in the config/main.php
:
'behaviors'=>array(
'class'=>'application.components.applicationBehavior',
),
would I use to do the settings on the application. If I run the controller to disable my application (Maintenance mode
) would then call in a way :
public function actionTurnoff()
{
Yii::app()->setGlobalState('massLogout',true);
$this->render('turnoff');
}
All users will stop automatically, unless the user that I use the username: bertho
.
The problem is now when I (username: bertho
) log out, then I will lose control
to get into my application back.
How should I create a code that if a normal user (without login
) are not affected by this behavior?
I have tried to examine the conditions :
$user = $owner->user->name;
and then :
if($user!='Guest'){
if($owner->getGlobalState('massLogout') && $user=='bertho'){
$owner->user->clearStates();
$owner->catchAllRequest=array('maintenance','view'=>'index');
}
}
But it always error : session_regenerate_id(): Session object destruction failed
.
What should I do?