4

I am having custom array like:

[business] => Array
(
    [55] => Array
    (
        [id] => 1
        [name] => abc
        [contact] => 1325467897
    ),
    [96] => Array
    (
        [id] => 5
        [name] => xyz
        [contact] => 9876543210
    )

)

This array is derived from conditional (if-else) multiple queries. So, I just want to add pagination on array. Can somebody suggest me how to add custom pagination on this type of array using standard paginator of CakePHP 3.

Oops D'oh
  • 941
  • 1
  • 15
  • 34

1 Answers1

-2

The PaginatorComponent can take a Cake\ORM\Query as it's thing to paginate, so I would suggest passing your compiled query object to the paginator.

So in your controller you could do something like the following.

public function example()
{
    $this->paginate = ['limit' => 5];

    $query = $this->Examples->find();

    if ($something === 'foo') {
        $query->where(['foo' => $something]);
    }

    if ($wtfbbq) {
        $query->contain(['Wtfs', 'Barbeques']);
    }

    $results = $this->paginate($query);
}

This will produce a Cake\ORM\Query with the pagination built in. Then you can adjust the pagination parameters as you see fit, by checking the book page on the Paginator.

David Yell
  • 11,756
  • 13
  • 61
  • 100