How to render a view inside a view?

Hi!

I’m a newbie in Yii trying to make something that seems quite basic, but I can’t figure out how should I do it.

I have a view with a grid that shows some data (‘zii.widgets.grid.CGridView’) and set of tabs (‘zii.widgets.jui.CJuiTabs’) that allow the user to select some operations to perform over data.

After the operation is selected I would like to show in the same view but in another grid the results of the operation to allow the user to compare both grids.

I’ve tried declaring the second grid inside another view (_viewrollup) and after the operation is performed the controller should ONLY render _viewrollup, but this is not working as expected (it shows the contents of _viewrollup but not inside the mani view.

This is the code of the main view




//operators tab

$this->widget('zii.widgets.jui.CJuiTabs',array(

        'tabs'=>array(

		'Roll up'=>$this->renderPartial('_view_rollupTab',array('dimensions'=>$dimensions, 'model'=>$rollup),true),

		'Slice'=>$this->renderPartial('_view_sliceTab',array(),true),

		'Dice'=>$this->renderPartial('_view_diceTab',array(),true),

		),

	// additional javascript options for the tabs plugin

	'options'=>array(

	'collapsible'=>true,

	),  

	'htmlOptions'=>array('class'=>'shadowtabs'),

));


?>


<h2>Base Facts</h2>

<?php


//base data grid

$this->widget('zii.widgets.grid.CGridView', array(

	'dataProvider' => $cubeDataProvider

));


?>

<h2>Operation Results</h2>


<?php

//operation results grid

$this->render('_viewrollup',array(

			'rollupDataProvider'=>NULL,

		));

?>



This is the code of _viewrollup




<?php

if ( $rollupDataProvider){

	//data grid

	$this->widget('zii.widgets.grid.CGridView', array(

		'dataProvider' => $rollupDataProvider

	));

}

?>



And this is the code inside the controller





$this->render('_viewrollup',array(

					'rollupDataProvider'=>$rollupDataProvider,

					));

		    

			}



any help would be appreciated :)

thanks

Lorena

try


$this->renderPartial();

for the nested view

Hi bettor,

thanks for your reply but this does not solve my problem :(

I agree with you that inside the main view I should use renderPartial instead of render, BUT the problem is [color="#FF0000"]what[/color] should I have to render in the controller after the action is executed.

If I say render(_viewrollup …) what I obtain is only the second grid with the layout of my site applied.

If I say renderPartial(_viewrollup …) I obtain only the second grib but without the layout.

thanks again

Lorena

Hi,

I am also having the same problem. Have u got a solution to this problem… if yes please… explain.

Thanks in advance

Regards

Hi guys,

I think your problem relates more to application design than actual Yii.

Have you tried using AJAX in your code? It could be a solution, rendering the data with JQuery.

Have a look:




Yii::app()->clientScript->registerScript('grid-form', "

$('.grid-form form').submit(function(){

    $.fn.yiiGridView.update('new-grid', {

        data: $(this).serialize()

    });

    return false;

});

");



Hope it helps.

Alejandro.