2017 © Pedro Peláez
 

symfony-bundle paginator-bundle

Simple paginator for Symfony2

image

arturdoruch/paginator-bundle

Simple paginator for Symfony2

  • Monday, May 14, 2018
  • by arturdoruch
  • Repository
  • 0 Watchers
  • 0 Stars
  • 313 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 4 % Grown

The README.md

PaginatorBundle

Simple paginator for Symfony2, which can paginate: * array * Doctrine\ORM\Query * Doctrine\ORM\QueryBuilder * Doctrine\ODM\MongoDB\Query\Builder * Doctrine\ODM\MongoDB\Query\Query * Doctrine\MongoDB\CursorInterface * MongoCursor, (*1)

Installation

Add the following line to your composer.json require block, (*2)

"require": {
    ...
    "arturdoruch/paginator-bundle": "~1.0"
}

and run composer command, (*3)

composer update arturdoruch/paginator-bundle

or simply, (*4)

composer require arturdoruch/paginator-bundle

Register ArturDoruchPaginatorBundle in your application kernel class, (*5)

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

Configuration

// app/config/config.yml

artur_doruch_paginator:
    limit: 10                        # Default value of displayed items per page
    prev_page_label: '← Prev'  # Pagination previous page button label
    next_page_label: 'Next →'  # Pagination next page button label

Usage

Controller

Get paginator in controller method., (*6)

$paginator = $this->get('arturdoruch_paginator');

Paginate items list., (*7)

$paginator->paginate($query, $page, $limit);

ArturDoruch\PaginatorBundle\Paginator::paginate() method receive three parameters: * $query (mixed) A Doctrine ORM query or query builder, Doctrine mongodb ODM query or query builder, instance of Doctrine\MongoDB\CursorInterface, instance of MongoCursor, or array with arrays of items. * $page (integer) Number of page to display * $limit (integer) The number of items per page. Possible values are: * -1 - fetch all items (limit will be omitted) * 0 - default limit (setting in config "artur_doruch_paginator.limit") will be used * integer positive - given $limit value will be used, (*8)

Examples

Paginate items with Doctrine ORM query and query builder., (*9)

// AppBundle\Controller\ProjectController.php

public function listAction($page, Request $request)
{
    $repository = $this->getDoctrine()->getRepository('AcmeProjectBundle:Project');
    $paginator = $this->get('arturdoruch_paginator');

    // Doctrine\ORM\QueryBuilder
    $qb = $repository->createQueryBuilder('p')
        ->select('p');

    $projects = $paginator->paginate($qb, $page, 5);

    // Doctrine\ORM\Query
    $query = $repository->createQueryBuilder('p')
        ->select('p')
        ->getQuery();

    $projects = $paginator->paginate($query, $page, 5);    

    return $this->render('AppBundle:Project:list.html.twig', array(
        'projects' => $projects
    ));
}

Paginate items with Doctrine ODM MongoDB query and query builder., (*10)

// todo

Paginate items with Doctrine\MongoDB\CursorInterface and MongoCursor., (*11)

// todo

Paginate items from array. Array can contain array or object collection., (*12)

// AppBundle\Controller\ProjectController.php

public function listAction($page, Request $request)
{
    $projectsList = array(
            array(
                'id' => 1,
                'name' => 'PHP'
            ),
            array(
                'id' => 2,
                'name' => 'JS'
            ),
            array(
                'id' => 3,
                'name' => 'Symfony'
            ),
            array(
                'id' => 4,
                'name' => 'Github'
            ),
            array(
                'id' => 5,
                'name' => 'SCSS'
            )
            ...
        );

    $paginator = $this->get('arturdoruch_paginator');
    $projects = $paginator->paginate($projectsList, $page, 5);

    return $this->render('AppBundle:Project:list.html.twig', array(
        'projects' => $projects
    ));
}

View

In twig template you can use several functions to display all paginate list data. Each of them require Pagination class instance as parameter. See example below., (*13)

{# Pagination #}
{{ arturdoruch_pagination(projects.pagination) }}

{# Displayed items range #}
{{ arturdoruch_pagination_displayed_items(projects.pagination) }}

{# Total items count #}
{{ arturdoruch_pagination_total_items(projects.pagination) }}

{# Renders all pagination parts: pagination, items range, total items #}
{{ arturdoruch_pagination_all(projects.pagination) }}



{% for project in projects %} {% endfor %}
Id Name
{{ project.id }} {{ project.name }}

The Versions

14/05 2018

dev-master

9999999-dev

Simple paginator for Symfony2

  Sources   Download

MIT

The Requires

 

by Artur Doruch

symfony2 bundle pagination paginator

14/05 2018

1.1.2

1.1.2.0

Simple paginator for Symfony2

  Sources   Download

MIT

The Requires

 

by Artur Doruch

symfony2 bundle pagination paginator

01/02 2017

1.1.1

1.1.1.0

Simple paginator for Symfony2

  Sources   Download

MIT

The Requires

 

by Artur Doruch

symfony2 bundle pagination paginator

24/08 2016

1.1.0

1.1.0.0

Simple paginator for Symfony2

  Sources   Download

MIT

The Requires

 

by Artur Doruch

symfony2 bundle pagination paginator

06/12 2014

v1.0.0

1.0.0.0

Simple paginator for Symfony2

  Sources   Download

MIT

The Requires

 

by Artur Doruch

symfony2 bundle pagination paginator