gpslab/pagination-bundle

Pagination bundle

Installs: 338

Dependents: 0

Suggesters: 1

Security: 0

Stars: 11

Watchers: 1

Forks: 1

Open Issues: 2

Type:symfony-bundle

v1.3.0 2019-11-08 10:18 UTC

This package is auto-updated.

Last update: 2019-12-08 10:44:39 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

class ArticleController extends Controller
{
    private const PER_PAGE = 30; // articles per page

    public function index(Request $request): Response
    {
        $rep = $this->getDoctrine()->getRepository(Article::class);

        $total = $rep->getTotalPublished();
        $total_pages = ceil($total / self::PER_PAGE);

        // build pagination
        $pagination = $this->get('pagination')->paginateRequest($request, $total_pages);

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

        return $this->render('AcmeDemoBundle:Article:index.html.twig', [
            'total' => $total,
            '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