Yii Framework Forum: Instance Gridview Widget With Model Relation Data - Yii Framework Forum

Jump to content

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

Instance Gridview Widget With Model Relation Data Rate Topic: -----

#1 User is offline   zwobbel 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 13-November 10

Posted 24 January 2013 - 09:32 AM

I have a model that results me an array of objects and when i loop trough i want to make several instances of widget gridview and pass along an array of object that comes from a relation, however the gridview is expecting a dataprovider and i'm not sure how to convert my data.

I have searched arround and someone else had the same issue but it was not solved:
http://stackoverflow...els-association

Anyone an idea what the best approach is to solve this issue?
0

#2 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,044
  • Joined: 16-February 11
  • Location:Japan

Posted 24 January 2013 - 10:29 AM

Hi zwobbel,

Did you try CArrayDataProvider? If you did, what was wrong with it? Could you explain your data and your needs a little more, probably with a pseudo code?
0

#3 User is offline   zwobbel 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 13-November 10

Posted 24 January 2013 - 10:47 AM

What i tried to do in pseudo code (this is a lite version of what i do) is for example:

<?php
//Controller
$model = Tickets::model()->with('changes')->findByPk(4);

//view
foreach($model as $model) {
print $model->title;
//Show the gridview 
  $this->widget('zii.widgets.grid.CGridView', array(                                                 
  'dataProvider' => $model->changes,                                                             
  'columns'=>array(                                                                                                                                                                            
    'name',                                                                                                                                                                                  
  ),                                                                                                 
));
}
?>


However, i know that the relation 'changes' will return an array objects and so its not a dataProvider.
I also tried to use the solution of stack overflow, however it did not worked it returned a php error that told me that there was no object or value or something like that..
0

#4 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,044
  • Joined: 16-February 11
  • Location:Japan

Posted 24 January 2013 - 11:03 AM

Something like this won't work?
<?php
//Controller
$models = Tickets::model()->with('changes')->findAllByAttributes(...);

//view
foreach($models as $model) {
  print $model->title;
  //Show the gridview
  $dataProvider = new CArrayDataProvider($model->changes);
  $this->widget('zii.widgets.grid.CGridView', array(                                                 
    'dataProvider' => $dataProvider,
    'columns'=>array(                                                                                                                                                                            
      'name',                                                                                                                                                                                  
    ),                                                                                                 
  ));
}

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