knp-components icon indicating copy to clipboard operation
knp-components copied to clipboard

make pagination limit configurable globally

Open gondo opened this issue 10 years ago • 7 comments

currently pagination limit default value is harcoded in function declaration https://github.com/KnpLabs/knp-components/blob/master/src/Knp/Component/Pager/Paginator.php#L83 however passing $limit = null cause exception: https://github.com/KnpLabs/knp-components/blob/master/src/Knp/Component/Pager/Paginator.php#L87 this is a problem when im trying to set options like this: $paginator->paginate($query, 1, null, array(...)); basically this construction force me to specify proper $limit every time i call paginate()

it would be much better if $limit was in $defaultOptions as this way i could set $limit on one place (in Symfony2 it would be config.yml) globally for every paginator.

gondo avatar May 25 '14 21:05 gondo

It would be nice

salemgolemugoo avatar May 16 '15 21:05 salemgolemugoo

I propose to change this interface in 2.0 to

interface PaginatorInterface
{
    function paginate($target): PaginationInterface;
    function withPage(int $page): PaginatorInterface
    function withLimit(int $limit): PaginatorInterface
    function withOptions(array $options): PaginatorInterface
}

Where in default implementation:

  • with* methods will be immutable setters. This will help dealing with cases when there is multiple paginators on single page
  • default $page will be inferred from request, as is currently done for sorting. There is even already pageParameterName, but is currently unused.
  • default $limit will be inferred from defaultOption

ping @polc

ostrolucky avatar Nov 11 '17 14:11 ostrolucky

You can open a PR on branch 2.0 if change is BC-breaking (like changing interfaces). If instead you simply add an option, you can open a PR on master branch

garak avatar Jun 21 '19 09:06 garak

I thought there will be more time until release of 2.0, now it's too late to do BC breaking change

ostrolucky avatar Jun 27 '19 07:06 ostrolucky

If this issue is still relevant I can open PR to add $limit to $defaultOptions (without BC break).

daria-sieroshtan avatar Jul 08 '20 13:07 daria-sieroshtan

It's still relevant. At the same time, I'm not sure what you plan to do. If you add it to $options, it will ignore limit specified in $page.

ostrolucky avatar Jul 08 '20 14:07 ostrolucky

Default limit value will be set in $defaultOptions, not hardcoded in function itself.

  • Explicitly passing $limit as an argument will work as previously.
  • Passing null and getting default limit will be possible while setting other options, like mentioned $paginator->paginate($query, 1, null, array(...));
  • Later with a wrapper functionality in the KnpPaginatorBundle default limit will be configurable globally, as other default options.

daria-sieroshtan avatar Jul 09 '20 08:07 daria-sieroshtan