2016-07-12 23 views
0

自分のアカウントにログインしているユーザーのユーザー名と電子メールのような詳細を表示しようとしています。私はyiiフレームワークのデフォルトのログインを使用しており、私はユーザを認証するprofileテーブルを持っています。実際には、ユーザーのユーザー名をパラメーターとして渡そうとしています。これはユーザー名とパスワードを確認するログインアクションです。デフォルトLoginFromモデルデータでデフォルトログインでのユーザーの詳細の検索

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

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, 
     ]); 


    } 
関連する問題