Render a view inside a view

I have two tables in my database, TableA and TableB. I used the Gii tool (which by the way is awesome) to create controllers, models and CRUD forms for the tables.

My problem is when i try to render TableA’s create form inside a CJuiDialog modal inside TableB’s view. The idea is to be able to create new entries of TableA without leaving the create form of TableB.

The code from _form.php of TableB that i added at the top is:

$this->beginWidget('zii.widgets.jui.CJuiDialog', array('id'=>'tableA')); // and some options too



This does not work and i get an error about ‘Undefined variable: model’ inside TableA/create.php.

I assume this is due to the $model variable inside the controller of TableA is not in scope. But how can i fix this?

pretty easy:

$this->renderPartial('...view...', array('model'=>$model));

To create multiple models with one view you would have to do something like this (assuming that the TableA model always has a TableB model)


public function actionCreate()


                $tableAModel=new tableAModel;

                $tableBModel=new tableBModel;

		// Uncomment the following line if AJAX validation is needed

		// $this->performAjaxValidation($model);









                $valid = $tableAmodel->validate();

                $valid = $tableAmodel->validate() && $valid;












Then you would use:

$this->renderPartial('tableBModel/_create.', array('model'=>$tableBModel));