duanmin0941 2014-07-18 16:21
浏览 15

如何在使用批量注销时扩展行为

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?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 划分vlan后不通了
    • ¥15 GDI处理通道视频时总是带有白色锯齿
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)
    • ¥15 自适应 AR 模型 参数估计Matlab程序
    • ¥100 角动量包络面如何用MATLAB绘制
    • ¥15 merge函数占用内存过大
    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大