0

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?

  • 3
    This isn't a failure. This is exactly the point of pagination. – Greg Schmidt May 12 '20 at 14:17
  • It will always give you a default number which in this case it's 20 results. From my experience, I wouldn't implement a pagination with more than 20 results. It would be kind of pointless. An example would be to do something like this ``$this->paginate = [ ‘page’ => 1, ‘limit’ => 10, ‘maxLimit’ => 10 ]; `` In this case, you would have 10 results per page, thus 10 platos/page 1, 10 platos/page 2 – Oris Sin May 12 '20 at 14:26

1 Answers1

0
$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

labec
  • 1
  • 1