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.
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