multiple views in one
Posted 16 July 2010 - 03:27 AM
I'm quite new to Yii and I'm trying to get a view where I combine several views in one.. I have 6 different models I want to show on one page, it works well when I use the CGridView but I need a CDetailView of one of the models but somehow I don't know how to declare a model. I generated the models, controllers, views with gii so I have the respective files (models: Model1.php, Model2.php..., controllers: Model1Controller.php,..., views...). If I for example want to have the detail view of Model1 and adjust the view of that model accordingly then I have no problem. If I make a new file newView.php and put some code in there I don#t get a model..
I hope that was somehow clear and there is somebody who can help me.
Posted 16 July 2010 - 04:35 AM
If you want to show this model you should have the id or some way for get it, so do like that:
<?php $this->widget('zii.widgets.CDetailView', array( 'data'=>ModelX::model()->findByPk($pk), 'attributes'=>array
This will load the modelX by fetching in database the pk in $pk.
Posted 16 July 2010 - 04:37 AM
However, if you just want to display multiple views in one parent view then you would use the renderPartial() function. http://www.yiiframew...r#renderPartial
Remember to pass all your models for each of the views into the parent view from the controller action that is rendering the parent view.
Posted 16 July 2010 - 06:38 AM
thanks for your answers
@zaccaria that was the thing I was searching for
@GDzyne I was trying the renderPartial() function but since I didn't know (still don't) how to pass a model into the parent view (I guess this was what I meant with declaring a model) it didn't work. The code looked like that:
but as I didn't specify the model it somehow didn't find what I was looking for