Ângelo Rigo
Ângelo Rigo

Reputation: 2157

CakePHP Pagination on array variable

I try to use the paginate class into CakePhp having the query results created by a custom method and not in the traditional CakePHP way .

At the end i have an array.

I try to apply the paginate into this array but did not see it paginating :

$myArray = $this->myModel->SearchDatabaseData( ); $myArray = $this->paginate('myModel');

The query is made into a Component so it claims for a Model instance instead PaginatorComponent::validateSort() must be an instance of Model, instance of VerificacaoComponent given

Can i apply CakePHP pagination into a custom made array ?

I am using CakePhp 2.5.

Upvotes: 1

Views: 1528

Answers (1)

Gestudio Cloud
Gestudio Cloud

Reputation: 290

You need to use Cakephp Custom query pagination. This requires 2 functions in your model, one with the query it self and another one with a count query with the same conditions.

When you try to paginate in your model, CakePhp has 2 global functions in the main AppModel, basically you will override this 2 functions rewriting them in your model.

This functions are: paginate() and paginateCount()

Once you override the AppModel functions with your custom version in your model, you can use regular $this->YourModelName->paginate(); in your controller.

You can find examples in this StackOverflow question: Custom Query Pagination Cakephp

You can check the original documentation here: http://book.cakephp.org/2.0/en/core-libraries/components/pagination.html#custom-query-pagination

Upvotes: 1

Related Questions