Pagination Not Working.


On a forum app I need to select the topics with its last post and the topics have to be ordered by its last post created date.

I’m using:

$topicsDP = new CActiveDataProvider('Topic', array(







        'joinType'=>'INNER JOIN',

        'order'=>Yii::app()->db->quoteColumnName('posts.created').' DESC',










When testing I have 4 topics, the first page is ok but the second isn’t. I think it is because the “OFFSET 3” is also affecting the posts select.

How can I do this?

Also, all posts are beeing select, is there some way of only selecting the last one?


Hi NCS_One,

I think that you have to do the lazy loading for the post objects.

You are now doing the eager loading … joining topic table and post table. In this case ‘order’, ‘limit’ and ‘offset’ will be applied to the virtually joined single table, not to the post table (nor to the topic table).

And when we use CActiveDataProvider with CPagination, it will automatically insert the ‘offset’ and ‘limit’ clauses according to the demand of the pagination, and they will overwrite your own ones.

I hope these wiki articles will be a little help.