Splitting a page into a custom array in CakePHP 3

I have a custom array, for example:

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

)

This array is obtained from conditional (if-else) multiple requests. So, I just want to add pagination to an array. Can anyone suggest me how to add custom pagination in this type of array using the standard CakePHP 3 paginator.

+4
source share
1 answer

PaginatorComponent can use Cake\ORM\Queryas an object for pagination, so I would suggest passing your compiled request object to paginator.

, - .

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);
}

Cake\ORM\Query . , , Paginator.

-2

Source: https://habr.com/ru/post/1611537/


All Articles