Estom_yin 2016-07-31 13:13 采纳率: 0%
浏览 3283
已结题

Yii2中 $app->user->login()执行,$app->user-identity仍为空

yii/models/loginForm
public function login()
{
if ($this->validate()) {
return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600*24*30 : 0);
}
return false;
}

public function getUser()
{
    if ($this->_user === false) {
        $this->_user = Users::findBystu_id($this->username);
        //if($this->_user == NULL) $SESSION['_role']

    }

    return $this->_user;
}
    验证函数没有问题,并且,能够通过数据苦衷用户名和密码的验证,登录页面能够输入正确的密码后能够正常的跳转到主页,但是$app->user-identity仍为空不能使用这个方法访问当前登录的用户
    class Users extends \yii\db\ActiveRecord implements \yii\web\IdentityInterface

{
public static function findBystu_id($stu_id)
{
$temp_ob = Users::find()->where(['stu_id'=>(int)$stu_id])->one();
return $temp_ob;
}
public function getId()
{
return $this->stu_id;
}
}
这是数据库users表对应的模型

  • 写回答

1条回答 默认 最新

  • 鱼弦 优质创作者: 编程框架技术领域 2016-07-31 13:47
    关注
    评论

报告相同问题?