1

I have page A with link :

<a href="/b?id=1"></a>

with controller BController.php like:

...

public function actionB(){
         $id = Yii::$app->request->getQueryParam("id");
        $model= new TestModel();
        $data = $model->find()->where(["id" => $id])->one();
        return $this->render('b',["data"=>$data]);

}

when link in A click , it redirect to views b views b.php just display value:

<?= $data->field_name?>

Now I can not see anything in views ,sure that in controller ,I can get data success

Please help me what wrong

7
  • getQueryParam("i") ........ should be getQueryParam("id"), I think Commented Apr 20, 2016 at 10:57
  • I'm sorry ,just typo mistake ,param get is correct in my source code and I can dump $data variable to see it Commented Apr 20, 2016 at 11:02
  • you can try $data = TestModel::find()->where(["id" => $id])->one(); return $this->render('b',["data"=>$data]); Commented Apr 20, 2016 at 11:06
  • var_dump($data); Check it contain any data. . Commented Apr 20, 2016 at 11:07
  • Any errors? if you do just return $this->render('b',["data"=>"Hello world"]); and in view <?= $data; ?> will it show you anything? if it will, ----> query didn't return anything.....what shows print_r($data)? Commented Apr 20, 2016 at 11:08

1 Answer 1

1

If you want pass id to actionB you should use

public function actionB($id){
     //$id = Yii::$app->request->getQueryParam("id");
    $model= new TestModel();
    $data = $model->find()->where(["id" => $id])->one();
    return $this->render('b',["data"=>$data]);

}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.