suzy 2015-09-15 15:25:22 4628次浏览 1条评论 5 0 0

1.在web.php文件中的‘user’配置中如下:

'user' => [
    'identityClass' => 'app\models\User',
    'enableAutoLogin' => true,
    'on afterLogin'=>function($event){
        $user=$event->identity;
        $model=new Log_Login();
        $model->USER_ID=$user->USER_ID;
        $model->USER_AGENT=$_SERVER['HTTP_USER_AGENT'];
        $model->IP=$_SERVER['REMOTE_ADDR'];
        $model->LOGIN=date("Y-m-d H:i:s");
        $model->save();
        $_SESSION['log_id']=$model->ID;
    },
    'on beforeLogout'=>function ($event){
        //$user=$event->identity;
        $model = Log_Login::findOne((int)$_SESSION['log_id']);
        $model->LOGOUT=date("Y-m-d H:i:s");
        $model->update();
    }
]
  • 评论于 2015-09-17 16:43 举报

    `'user' => [

    'identityClass' => 'app\models\User',
    'enableAutoLogin' => true,
    'on afterLogin'=>function($event){
        $user=$event->identity;
        $model=new Log_Login();
        $model->USER_ID=$user->USER_ID;
        $model->USER_AGENT=$_SERVER['HTTP_USER_AGENT'];
        $model->IP=$_SERVER['REMOTE_ADDR'];
        $model->LOGIN=date("Y-m-d H:i:s");
        $model->save();
        $_SESSION['log_id']=$model->ID;
    },
    'on beforeLogout'=>function ($event){
        //$user=$event->identity;
        $model = Log_Login::findOne((int)$_SESSION['log_id']);
        $model->LOGOUT=date("Y-m-d H:i:s");
        $model->update();
    }
    

    ]`

您需要登录后才可以评论。登录 | 立即注册