在默认登录中查找用户的详细信息


Finding the details of user in default login

我正在尝试显示登录其帐户的用户的用户名和电子邮件等详细信息。我正在使用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,
        ]);

    }

默认情况下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,
        ]);

    }