gpslab/pagination-bundle

Pagination bundle

Installs: 595

Dependents: 0

Suggesters: 1

Security: 0

Stars: 11

Watchers: 2

Forks: 2

Open Issues: 4

Type:symfony-bundle

v1.4.2 2020-03-19 18:07 UTC

This package is auto-updated.

Last update: 2024-11-20 04:40:14 UTC


README

Latest Stable Version PHP from Travis config Build Status Coverage Status Scrutinizer Code Quality StyleCI License

PaginationBundle

Pagination page 1

Pagination page 4

Pagination page 9

Installation

Pretty simple with Composer, run:

composer req gpslab/pagination-bundle

Configuration

Default configuration

gpslab_pagination:
    # Page range used in pagination control
    max_navigate: 5

    # Name of URL parameter for page number
    parameter_name: 'page'

    # Sliding pagination controls template
    template: 'GpsLabPaginationBundle::pagination.html.twig'

Simple usage

use GpsLab\Bundle\PaginationBundle\Service\Configuration;

class ArticleController extends Controller
{
    private const ARTICLES_PER_PAGE = 30;

    public function index(ArticleRepository $rep, Configuration $pagination): Response
    {
        $pagination->setTotalPages(ceil($rep->getTotalPublished() / self::ARTICLES_PER_PAGE));

        // get articles chunk
        $offset = ($pagination->getCurrentPage() - 1) * self::ARTICLES_PER_PAGE;
        $articles = $rep->getPublished(self::ARTICLES_PER_PAGE, $offset);

        return $this->render('AcmeDemoBundle:Article:index.html.twig', [
            'articles' => $articles,
            'pagination' => $pagination
        ]);
    }
}

Display pagination in template:

<nav class="pagination">
    {{- pagination_render(pagination) -}}
</nav>

Documentation

License

This bundle is under the MIT license. See the complete license in the file: LICENSE