Skip to content

gpslab/pagination-bundle

Repository files navigation

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