tab
(Tarab)
November 9, 2013, 12:33pm
1
Hi,
I am trying to render another view in my main view in but I have an error of not found variable .
I hope my example explains my problem:
in my view_a/index I have this code
$this->render('/view_b/index',array('id'=>$id));
echo '<a href="'.Yii::app()->createUrl('/view_b/index',array('id'=>$id)).'">show</a>';
Why the render doesn’t works and the link correctly works?
tab:
Hi,
I am trying to render another view in my main view in but I have an error of not found variable .
I hope my example explains my problem:
in my view_a/index I have this code
$this->render('/view_b/index',array('id'=>$id));
echo '<a href="'.Yii::app()->createUrl('/view_b/index',array('id'=>$id)).'">show</a>';
Why the render doesn’t works and the link correctly works?
Make sure you have passed $id to renderPartial call, i. e. <?= $this->renderPartial(‘your_partial’, array(‘id’ => $id));
tab
(Tarab)
November 9, 2013, 1:57pm
3
Yes I’m sure.
If I use
$this->render('/view_b/index',array('id'=>1));
I have: Undefined variable: name_variable
If I use
$this->render(Yii::app()->createUrl('/view_b/index',array('id'=>1)))
It prints: A_Controller cannot find the requested view "/mysite/view_b/index/id/1
Ok, let’s make it clear.
Here’s how you render views from action:
// FirstController.php
public function actionIndex()
{
$id = 1;
// renders firstController/index.php
$this->render('index', array('id' => $id));
// renders anotherControllerName/index.php
$this->render('/anotherController/index', array('id' => $id));
and here’s how you render view from another view:
// firstController/index.php
// renders anotherControllerName/index.php
<?= $this->renderPartial('/anotherController/index', array('id' => $id)); ?>
PS. I don’t remember exactly, but maybe it’s required to use // instead of / in the beginning of view path, i.e. $this->renderPartial(’// anotherController/index’)
Function createUrl is used for url creation ONLY.