display multiple models in one view

How can I display two different model in one view. How can I pass two models into the controller?



plez explain in detail how to display 2 different model in one view…

There’s nothing special. :)

// in the controller

$model1 = ModelA::model()->findByPk($model1_id);

$model2 = ModelB::model()->findByPk($model2_id);

$this->render('myView',array('model1'=>$model1, 'model2'=>$model2)); 

// in the view

echo "<p>Model A Name = " . $model1->name . "</p>";


echo "<p>Model B Name = " . $model2->name . "</p>";

// Or, in the view

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








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








I do this in admin view (displaying 2 models).

Why edit/view buttons from both gridviews are linked to the first model?

can you post your controller please ?

	public function actionAdmin()


		$model=new AfterTasksDsm('search');

		$model->unsetAttributes();  // clear any default values


		$model2=new AfterTasksFb('search');