Search code examples
phpyiipaginationdataprovider

How to create my own DataProvider in Yii using CDataProvider?


I am in a situation like this below. I am fetching some data using CSqlDataProvider and its pagination (page size) which internally uses limit and offset. And after that I get

$rawData = $sqldp->getData();

Now I need to do some processing and adding additional data. So now I get

$modRawData = modification($rawData);

Now If I create one CArrayDataProvider to convert it into a Dataprovider so that I can use the CListView.

But My problem is here. Now I am unable to do Pagination. If I use CLinkPager its possible. But is there any other way so that I can create my own DATAPROVIDER and can handle the pagination while creating the dataProvider.


Solution

  • At last I got the answer. And yes I can create my custom DataProvider by extending CDataProvider. But I needed to only implement three functions

    fetchData, fetchKeys, calculateTotalItemCount

    And lastly you need to write your own logic into fetchData as you want.