Skip to content

Commit 3e4eb2a

Browse files
authored
Merge pull request #8134 from cakephp/5.next-limit
Docs for limitControl() enhancements.
2 parents 67eebae + 498dc82 commit 3e4eb2a

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

en/appendices/5-3-migration-guide.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,3 +239,9 @@ View
239239

240240
- ``ViewBuilder::getConfigMergeStrategy()`` was added to retrieve the current merge
241241
strategy setting.
242+
243+
- :php:meth:`PaginatorHelper::limitControl()` now automatically respects the
244+
``maxLimit`` configuration from the paginator, filtering out any limit options
245+
that exceed it. A new ``steps`` option was added to automatically generate limit
246+
options in multiples of a specific value (e.g., ``['steps' => 10]`` generates
247+
10, 20, 30... up to maxLimit).

en/views/helpers/paginator.rst

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,42 @@ Create a dropdown control that changes the ``limit`` query parameter::
430430

431431
The generated form and control will automatically submit on change.
432432

433+
Automatic Limit Generation with Steps
434+
--------------------------------------
435+
436+
Instead of manually defining limit options, you can use the ``steps`` option to
437+
automatically generate limits in multiples of a specific value::
438+
439+
// Generate limits in steps of 10 up to maxLimit
440+
echo $this->Paginator->limitControl([], null, ['steps' => 10]);
441+
// With maxLimit of 50, this generates: 10, 20, 30, 40, 50
442+
443+
// Steps of 25 up to maxLimit or 100 (whichever is lower)
444+
echo $this->Paginator->limitControl([], null, ['steps' => 25]);
445+
446+
When using ``steps``, you cannot also provide explicit limits in the ``$limits``
447+
parameter - you must use one or the other.
448+
449+
Respecting maxLimit
450+
-------------------
451+
452+
The ``limitControl()`` method automatically respects the ``maxLimit`` configuration
453+
from your paginator settings. Any limit options that exceed the ``maxLimit`` will
454+
be automatically filtered out::
455+
456+
// In your controller with maxLimit of 50
457+
$this->paginate = [
458+
'limit' => 20,
459+
'maxLimit' => 50,
460+
];
461+
462+
// In your template - limits above 50 are filtered out
463+
echo $this->Paginator->limitControl([20 => 20, 50 => 50, 100 => 100]);
464+
// Only shows: 20, 50
465+
466+
If all default or provided limits exceed the ``maxLimit``, the control will
467+
automatically use the ``maxLimit`` value as the only available option.
468+
433469
Configuring Pagination Options
434470
==============================
435471

0 commit comments

Comments
 (0)