Cakephp compact array

281 Views Asked by At

In my function index() this code not return all

$this->paginate = [
        'contain' => ['TipoPlatos','TipoArticulos'],
    ];
    $platos = $this->paginate($this->Platos);

$this->set(compact('platos'));

This only return 20 platos but i have 23.

If y use this

$platos2 = $this->Platos->find('all')->select(['id'])->toArray();

i have all, but i dont know why the first dont return all.

Can the failure be obtained from the paginate?

1

There are 1 best solutions below

0
On
$this->paginate = [
        'contain' => ['TipoPlatos','TipoArticulos'],
    ];
    $platos = $this->paginate($this->Platos);

$this->set(compact('platos'));

^ this is using pagination https://book.cakephp.org/3/en/controllers/components/pagination.html
which will help you doing urls like:

your-site.test/platos // <= page 1
your-site.test/platos?page=2
your-site.test/platos?page=3

If you want the index to return all, change your code to:

$platos = $this->Platos->find()
    ->contain(['TipoPlatos','TipoArticulos'])
    ->all();

$this->set(compact('platos'));

https://book.cakephp.org/3/en/orm/retrieving-data-and-resultsets.html#using-finders-to-load-data