whiteoctober / Pagerfanta

Pagination for PHP.
Other
1.59k stars 2 forks source link

Pagination Config #212

Open sylvan-d-ash opened 8 years ago

sylvan-d-ash commented 8 years ago

Hi,

Is there a config setting for specifying the default maximum number of items per page? I'm using Sylius which comes with Pagerfanta, but so far I haven't been able to find a config for this short of altering the vendor files

sstok commented 8 years ago

https://github.com/whiteoctober/Pagerfanta/blob/master/src/Pagerfanta/Pagerfanta.php#L129

kklecho commented 7 years ago

Apparently there is no. It would be good to have one configured for entire app the same way as exception strategy.

cezzre commented 7 years ago

Hi @winter7621, as @sstok has pointed out, you can use the method setMaxPerPage.

@kshishkin If setting a value as default is what you want, you can extend the class Pagerfanta and customise the __construct() to set your preferred setMaxPerPage.

For instance:

namespace AppBundle\Model;

use Pagerfanta\Pagerfanta; use Pagerfanta\Adapter\AdapterInterface;

class MyCustomPagerfanta extends Pagerfanta { public function construct(AdapterInterface $adapter) { parent::construct($adapter); $this->setMaxPerPage(/ your preferred value /); } }

sampart commented 7 years ago

Hi @winter7621,

It looks like Sylius itself exposes an option for you in its routing configuration: http://docs.sylius.org/en/latest/bundles/SyliusResourceBundle/index_resources.html#changing-the-max-per-page-option-of-paginator

For example (from their docs linked to above):

# app/config/routing.yml

app_book_index_top:
    path: /books/top
    methods: [GET]
    defaults:
        _controller: app.controller.book:indexAction
        _sylius:
            paginate: 5
            sortable: true
            sorting:
                score: desc
            template: Book/top.html.twig

This changes the max-per-page to 5.

Hope this helps!