How can I display two different model in one view. How can I pass two models into the controller?
thanks
How can I display two different model in one view. How can I pass two models into the controller?
thanks
$this->render('myView',array('model1')=>$model1,'model2'=>$model2); 
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(
	'data'=>$model1,
	'attributes'=>array(
		'name',
		'something',
		...
);
...
$this->widget('zii.widgets.CDetailView', array(
	'data'=>$model2,
	'attributes'=>array(
		'name',
		'something_different',
		...
);
Hi,
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');
		$model2->unsetAttributes();
		if(isset($_GET['AfterTasksDsm']))
			$model->attributes=$_GET['AfterTasksDsm'];
		$this->render('admin',array(
			'model'=>$model,
			'model2'=>$model2
		));
	}