display more than one model on a CGridView


Imagine I’d like to show on a grid the last 5 posts of a user. Each row of the grid shows a post. Additionally, for every post I’d like to have subrows, each one showing one person involved in the post at a time.

The models I have are Post and User. I mapped posts and users and pass it as an array to the CGridView with no luck.

So, is it posible to display data from more than one model on a CGridView?


I’m not terribly familiar with the CGridView but instead of using the CActiveDataProvider in your controller you could use a CSqlDataProvider and write a custom query. You’re not taking advantage of the model architecture then but it would allow you to do what you’re asking.


nazum, thanks. I’ll look into it and get back.

There is an example in this thread.

thanks enfield. Not exactly what I need it but I learned a lot from it.

Anyway, I think is best if I close this thread since I explain the whole problem properly here