如何在yii中注册后自动登录和重定向? [英] How to Auto Login and Redirect After Registration in yii?

查看:86
本文介绍了如何在yii中注册后自动登录和重定向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在自动登录后使用重定向功能时出现此错误:

When I use redirect function after auto login this error occur:

session_regenerate_id():会话对象销毁失败

session_regenerate_id(): Session object destruction failed

有人可以帮我吗?

<?php
public function actionRegister()
{
    $model = new UserProfileForm;

    $this->performAjaxValidation($model,'userProfile-form');

    if(isset($_POST['UserProfileForm']))
    {
        $model->attributes = $_POST['UserProfileForm'];
        if ($model->save()) 
        {
            $u = new LoginForm;
            $u->username = $model->username;
            $u->password = $model->password;
            $u->login();

            $this->redirect(Yii::app()->user->returnUrl);
        }
    }
    $this->render('register',array('model'=>$model,));
}

?>

推荐答案

以下作品.

if($model->save()){            

    $identity=new UserIdentity($model->username,$model->password);
    $identity->authenticate();
    Yii::app()->user->login($identity);

    $this->redirect(Yii::app()->user->returnUrl);                
}

PS:$model->save() 运行 $model->validate() 所以你在重复自己

PS: $model->save() runs $model->validate() so you are repeating yourself

这篇关于如何在yii中注册后自动登录和重定向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆