1

I use cakePHP 3.3 and I want to have a filter with the option to change the limit. This option should have the current limit selected.

What is the best way to get the current limit or results per page used in the Paginator in my view?

I use <?= $this->Paginator->counter('{{current}}'); ?> but this feels hacky and it is the limit as a string.
Also if the results are less than the limit, this will not show the limit but the number of found results.

  • You can create a variable with the number of pages to show, manually initialize the `paginator` as shown in the docs: http://book.cakephp.org/3.0/en/controllers/components/pagination.html and pass the variable to the view. I can't see an option to get the number of pages directly from the paginator in the docs – Alberto Méndez Nov 09 '16 at 11:20

1 Answers1

3

The paginator component adds pagination details to the request objects params, using the key paging, where the data is nested using the alias of the table object.

Check

debug($this->request->param('paging'));

This data is easily accessible in your view templates via the paginator helpers param() method.

$this->Paginator->param('perPage');

So, why perPage? you may ask. Well, while there is also a limit parameter, this will always be null unless you haven't explicitly set a limit value in the pagination options, and a limit value is being passed in the URL (at least unless the passed value doesn't match the default). I don't really get the point of this behavior, but well, that's how it is.

Anyways, currently these are the supported parameters:

  • count
  • current
  • direction
  • directionDefault
  • finder
  • limit
  • nextPage
  • page
  • pageCount
  • perPage
  • prevPage
  • scope
  • sort
  • sortDefault

See also

ndm
  • 59,784
  • 9
  • 71
  • 110