php - 在yii中注册后如何登录用户

标签 php authentication yii

我不确定如何在使用 yii 框架创建用户后立即登录。

在 UserController 中,我创建了 actionRegister 以允许用户创建新帐户,如果用户成功保存到数据库,我也想为该用户执行登录。这是我的代码:

    public function actionRegister()
    {
        $model=new User;

        if(isset($_POST['User']))
        {
            $model->attributes=$_POST['User'];

            if($model->save()){            

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

                $this->redirect(array('view','id'=>$model->id));                
            }
        }
        $this->render('register',array('model'=>$model));
    }

预先感谢您在这件事上能给我的任何帮助。

最佳答案

好吧,看来我是在回答我自己的问题......

事实证明 $this->redirect(array('view','id'=>$model->id)); 出于某些不明原因不允许登录发生。 . 自从我昨天开始学习 yii 以来,我无法回答这个问题,但如果有知识的人可以证明这一点,我将不胜感激。

所以解决方案就是删除重定向,我们在创建帐户后立即让用户登录。

感谢您尝试帮助 John 和 Jay =)

关于php - 在yii中注册后如何登录用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8215918/

相关文章:

php - 从 PHP 启动独立的 Python 进程

php - Yii CDbCriteria 选择带有 AS 别名

MongoDB "Connection refused"错误

PHP 特殊符号链接(symbolic link)用法

php - mysql 组到列

java - 使用 Java 为 Google App Engine 自定义基于 JWT 的身份验证

authentication - OpenID 提供程序可以使用 Kerberos 或其他 "alternate"身份验证机制吗?

c# - 无法从传输连接读取数据 : the connection was closed

php - 如何在不使用 PDO 的情况下改进 PHP 清理

php - 什么是 EXT_NOP 和 EXT_STMT,PHP Opcode