0
votes

I use a remote API to retrieve data (in xml, json format), which I'm caching. But I need to properly paginate this data before render.

I don't want to store this data in database.

I'm OK to recreate a PHPPaginator component and do the data manipulation by myself (Hash::sort, filtering, etc) like mentioned here but I would love to reuse the Pagination helper.

I tried to understand how the Paginator component transmits data to the Paginator helper but I couldn't find where it was instantiated and where the data was set.

I saw the $this->Paginator->settings gives for a classic model:

array(
'page' => (int) 1,
'current' => (int) 100,
'count' => (int) 341,
'prevPage' => false,
'nextPage' => true,
'pageCount' => (int) 4,
'order' => 'Model.created DESC',
'limit' => (int) 100,
'options' => array(),
'paramType' => 'named'
)

How should I instantiate the Paginator helper for it to autobuild all the links in the very same way as it does with normal data?

1

1 Answers

1
votes

Use the Array Data Source from this repository. Just turn your json file into an array or create your own Json Data Source based on it.

https://github.com/cakephp/datasources

The paginator just takes the URL params and turns them into a find('all') and find('count'). The helper just deals with generating some link in the view with the params for the paginator component. The real pagination happens by the find all and count using a model object.