Let’s say I have a model called User, who has many Pages and these Pages have many Comments.
On a user view with an $id as a parameter I want to load that user with all his pages and all the comments from all these pages.
public actionMyAction($id) {
$criteria = new CDbCriteria();
$criteria->condition = "t.id = $id";
$criteria->with = array('pages', 'pages.comments);
$model = User::model()->find($criteria); //or $model = User::model()->findAll($criteria);
}
$model has everything I need. If I use find() it returns an object, if I use findAll() it returns an array. In any case, it will return only 1 user as the IDs are unique.
Now, the only thing I can get is 1 row in the CGridView with the name of the user.
How can I show something like this:
User 1 | Page 1 | Comment 1
User 1 | Page 1 | Comment 2
User 1 | Page 1 | Comment 3
User 1 | Page 2 | Comment 1
User 1 | Page 2 | Comment 2
User 1 | Page 3 | Comment 1
Thanks