Yii Framework Forum: Getting Data For Cgridview From Many To Many Table - Yii Framework Forum

Jump to content

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

Getting Data For Cgridview From Many To Many Table Rate Topic: -----

#1 User is offline   Wilbo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 52
  • Joined: 06-September 13

Posted 24 September 2013 - 10:41 AM

Hi,

I have a table with two columns: user_id and post_id, linking certain users to certain posts.
How do I get the data from the posts table for a certain user and display each result in a CGridView?

I suppose my question is how do I construct the dataProvider?
I'm guessing a for each loop will be involved?

I have relations set up in the models for posts and users

Thanks in advance!
0

#2 User is offline   Wilbo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 52
  • Joined: 06-September 13

Posted 24 September 2013 - 11:14 AM

OK, after some more search found this amazing post which gives a great example of how to reference data from Many to Many relationships.

Now I just have to work out how to put it into a dataprovider. Any help with this would be greatly appreciated!
0

#3 User is offline   Gerhard Liebenberg 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 338
  • Joined: 07-January 12
  • Location:Stillbay - Western Cape - South Africa

Posted 24 September 2013 - 03:23 PM

Hi Wilbo

Try this wiki: Dynamic Parent and Child gridviews.

The users can be in the parent gridview, and each user's posts can be in the child gridview.
0

#4 User is offline   Wilbo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 52
  • Joined: 06-September 13

Posted 24 September 2013 - 03:25 PM

Hi Gerhard, thanks very much, I'll give that a read through.
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