Yii Framework Forum: multiple views in one - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

multiple views in one Rate Topic: -----

#1 User is offline   schlydi 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 16-July 10

Posted 16 July 2010 - 03:27 AM

Hi,

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.

schlydi
0

#2 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,232
  • Joined: 04-October 09
  • Location:Moscow

Posted 16 July 2010 - 04:35 AM

You should not "declare" a model, you should load from database.

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.
0

#3 User is offline   GDzyne 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 38
  • Joined: 15-June 09

Posted 16 July 2010 - 04:37 AM

Hi, please provide some of your code so that we can better understand your scenario.

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.
0

#4 User is offline   schlydi 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 16-July 10

Posted 16 July 2010 - 06:38 AM

Hi,

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:

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


but as I didn't specify the model it somehow didn't find what I was looking for ::)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users