facile-it/paginator-bundle

lightweight symfony2 pagination

Installs: 1 403

Dependents: 0

Stars: 3

Watchers: 14

Forks: 1

Language: PHP

v1.0 2014-08-26 14:02 UTC

README

A lightweight symfony2 pagination system

Build Status Code Climate

  • Twig>=1.5 version is required if you plan to include the twig template.

Features:

  • Inizialization can be made via request or via setters
  • Handle route as well as route parameters

Installation and configuration:

Quite easy Composer, add:

{
    "require": {
        "facile-it/paginator-bundle": "dev-master"
    }
}

Or if you want to clone the repos:

git clone git://github.com/facile-it/paginator-bundle.git vendor/facile-it/PaginatorBundle

Add PaginatorBundle to your application kernel

// app/AppKernel.php
public function registerBundles()
{
    return array(
        // ...
        new Facile\PaginatorBundle\FacilePaginatorBundle(),
        // ...
    );
}

Usage examples:

Controller

Currently paginator can paginate:

  • Doctrine\ORM\QueryBuilder
// Acme\MainBundle\Controller\ProductController.php


    $queryBuilder = $this
        ->get('doctrine.orm.entity_manager')
        ->getRepository('AcmeMainBundle:Product')
        ->createQueryBuilder('product')

    $paginator = $this->get('facile.paginator')->parseRequest($this->getRequest());

    return $this->render('AcmeMainBundle:Product:list.html.twig', array(
        'results' => $pagination,
        'paginationInfo' => $paginator->getPaginationInfo($filterBuilder
        )
    );

View

{# display results #}
<table>
    {% for product in results %}
        <tr >
            <td>{{ product.id }}</td>
            <td>{{ product.title }}</td>
        </tr>
    {% endfor %}
</table>

{# display navigation #}
<div class="navigation">
    {% include 'FacilePaginatorBundle:Pagination:template.html.twig' %}
</div>