我正在尝试显示登录其帐户的用户的用户名和电子邮件等详细信息。我正在使用yii框架的默认登录,我有profile
表,用于验证用户。实际上我试图将用户的用户名作为参数传递。这是检查用户名和密码的登录操作。
public function actionLogin()
{
if (!\Yii::$app->user->isGuest) {
return $this->redirect(Yii::$app->request->baseUrl.'/todo/index');
}
$model = new LoginForm();
if ($model->load(Yii::$app->request->post()) && $model->login() )
{
return $this->redirect(Yii::$app->request->baseUrl.'/todo/index/<?php echo $model->username;?>'); //this is how i like to pass the username as parameter
}
return $this->render('login', [
'model' => $model,
]);
}
答案 0 :(得分:0)
默认LoginFrom
模型数据位于getUser
函数
所以最终的代码是:
public function actionLogin()
{
if (!\Yii::$app->user->isGuest) {
return $this->redirect(Yii::$app->request->baseUrl.'/todo/index');
}
$model = new LoginForm();
if ($model->load(Yii::$app->request->post()) && $model->login() )
{
return $this->redirect(Yii::$app->request->baseUrl.'/todo/index/' . $model->getUser()->username); //this is how i like to pass the username as parameter
}
return $this->render('login', [
'model' => $model,
]);
}