Pagination Issue With Cactivedataprovider

Hi Guys - I’m having issue with pagination. I’m using it with cActiveDataProvider and not in CDBCriteria. Below is the detail:

  1. I’m using it in REST API. In REST API, I’m getting current_page and page_size. I’m setting it as it is.

  2. I’m having issue when the current_page is beyond the limit of pages. i.e. Imagine there are 2 pages only and if I’m setting current_page to 3 or 4 than it is returning the results of the last page however it should not return anything if the data on that page does not exist.

Please guide.


If I’m not mistaken, this is a standard way, how CActiveDataProvider works and how other components like this will work. I think, this is a so-called standard. For example, whenever I develop any kind of range checking, I always code it the way, like if an amount is higher then max, then it is set to max, not to return an empty result.

If this is the problem for you, then why don’t you write your own class, that will extend CActiveDataProvider (CPagination or CLinkPager, wherever problem lies) and change inside only a problematic function. Fix it yourself, so an empty resultset is returned (as you wish), not the last page.

For example, I had a bit different problem, that standard pagination widget available in Yii was either displaing pagination links (one per each page) – CLinkPager – or a dropdown list with all pages in one place – CListPager. And I wanted a widget that will display both of them at the same time. So I wrote my own pager, based on CBasePage, CLinkPager, CListPager and CPagination classes, that took "the best part of them" into one piece. Then, I forced CListView to use my own, not build-one pager.

Thanks Trejder, I’ll look into it in this way. Thanks for your guidance.