我不确定如何在使用 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/