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表对应的模型