SaSa 2016-04-14 09:44:43 1871次浏览 1条回复 0 0 0

控制器中

public function actionLogin()
{		
    if (!\Yii::$app->user->isGuest) {
        return $this->goHome();
    }
				
    $model = new LoginForm();
    if ($model->load(Yii::$app->request->post()) && $model->login()) {
        print_r($model);
        exit();
        //return $this->redirect(['view', 'id' => $model->UID]);
			
    }else{
				
        return $this->render('login',['model' => $model]);
    }
}

模型中

/**
     * Logs in a user using the provided username and password.
     * @return boolean 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
*/
public function getUser()
{
        if ($this->_user === false) {
            $this->_user = User::findByUsername($this->username);
        }

        return $this->_user;
}
您需要登录后才可以回复。登录 | 立即注册