有人可以建议我如何使用Yii2和MongoDB登录用户?我试过下面的例子,它们显示了同样的错误:
https://github.com/hipstercreative/yii2-user-mongo
https://github.com/sheillendra/yii2-user-mongo/tree/master
我逐个调试该函数,并从NULL
$this->getUser()
获取LoginForm.php
结果
public function login()
{
if ($this->validate()) {
return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600 * 24 * 30 : 0);
} else {
return false;
}
}
答案 0 :(得分:0)
/**
* Logs in a user using the provided username and password.
*
* @return bool whether the user is logged in successfully
*/
public function login() {
if ($this->validate()) {
return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600 * 24 * 30 : 0);
}
return false;
}
/**
* Finds user by [[username]]
*
* @return User|null
*/
protected function getUser() {
if ($this->_user === null) {
$this->_user = User::find()->where(['email' => $this->emailorphone])->orWhere(['phone' => $this->emailorphone])->one();
}
return $this->_user;
}