2017-03-15 17 views
1

私はlabel - > Profilを作成し、彼のURLを/ bloggers/viewに設定しましたが、ログインしてprofilを見てみるとエラーが表示されます。どのように問題を解決するか分からなかった!みんな助けてくれますか?なぜ私のactionViewはログインしているユーザーの$ id(私の場合はBlogger)を使用しないのですか?必要なパラメータがありません:Yii2のid actionView

public function actionView($id) 
    { 
     return $this->render('view', [ 
      'model' => $this->findModel($id), 
     ]); 
    } 

私はこのアクションをユーザーにregistratingています:

public function actionRegister() 
    { 
     $model = new RegisterForm(); 
     $user = new Blogger(); 

     if(isset($_POST['register-button'])) 
     { 
      $model->attributes = $_POST['RegisterForm']; 

      if($model->validate()) 
      { 
       $user->username = $model->username; 
       $user->email = $model->email; 

       $pass_hash = md5($model->password); 

       $user->password = $pass_hash; 
       $user->save(); 

       \Yii::$app->user->login($user); 
       $this->redirect('index'); 

      } 
     } 

     return $this->render('register',[ 
      'model' => $model, 
     ]); 
    } 

私はまだ初心者と私はコードで愚かthnigをしたmaybaハードですが、ご容赦くださいadvaceにありがとう!

答えて

0

actionViewは、Yii形式に従ってurlからidパラメータを取得します。

例: - domain.com/xxx?id=5またはdomain.com/xxx/id/6

あなたがログインしているユーザーIDを渡したい場合、あなたは

public function actionView() 
{ 
    $id = \Yii::$app->user->identity->id; // id should match with user table column 
    return $this->render('view', [ 
     'model' => $this->findModel($id), 
    ]); 
} 
ようactionViewを変更する必要があります
+0

おい、本当に..あなたは私の救い主です!どうもありがとうございます! –

関連する問題