PHP Classes

OKA Symfony Pagination Twig: Bundle for pagination support using Twig templates

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 34 All time: 11,026 This week: 206Up
Version License PHP version Categories
oka-pagination 2.7.0MIT/X Consortium ...5.3HTML, PHP 5, Libraries
Description 

Author

This package is a bundle for pagination support using Twig templates.

Applications should register the bundle to use its pagination features.

A class should be provided to implement an action to list the data to be displayed with pagination controls on a Web page.

The pagination output is defined using Twig templates. Several other aspects of the way pagination is generated can be configured with a separate file.

Picture of Cedrick Oka
  Performance   Level  
Name: Cedrick Oka <contact>
Classes: 1 package by
Country: Ivory Coast Ivory Coast
Age: ???
All time rank: 45111 in Ivory Coast Ivory Coast
Week rank: 200 Up1 in Ivory Coast Ivory Coast Equal

Documentation

Getting Started With OkaPaginationBundle

This bundle provides a flexible pagination system.

Prerequisites

The OkaPaginationBundle has the following requirements: - PHP 5.5 - Symfony 2.7+ - Twig Extension

Installation

Installation is a quick (I promise!) 4 step process:

  1. Download OkaPaginationBundle
  2. Enable the Bundle
  3. Configure the OkaPaginationBundle
  4. Use bundle and enjoy!

Step 1: Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

$ composer require coka/pagination-bundle

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

Step 2: Enable the Bundle

Then, enable the bundle by adding it to the list of registered bundles in the app/AppKernel.php file of your project:

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...
            
            new Oka\PaginationBundle\OkaPaginationBundle(),
        );
        
        // ...
    }

    // ...
}

Step 3: Configure the Bundle

Add the following configuration to your config.yml.

# app/config/config.yml
oka_pagination:
    db_driver: orm
    model_manager_name: default
    item_per_page: 10                                           # Global number of items to show by page
    max_page_number: 4000                                       # Global number max of page to show
    template: OkaPaginationBundle:Pagination:paginate.html.twig # Global twig template used for shown pagination menu
    request:
        query_map:
            page: page                                          # Global page query parameter name
            item_per_page: item_per_page                        # Global number of items by page query parameter name
            sort: sort                                          # Global sort field query parameter name
            desc: desc                                          # Global sort direction query parameter name
        sort:
            delimiter: ','                                      # Global sort query delimiter value
            attributes_availables: ['name']                     # Global sort query value availables attributes
    twig:
        enable_extension: true
        enable_global: false
    pagination_managers:
        foo:
            db_driver: orm
            model_manager_name: default
            class: Acme\DemoBundle\Entity\Foo
            item_per_page: 10
            max_page_number: 4000
            template: OkaPaginationBundle:Pagination:paginate.html.twig
            request:
                query_map:
                    page: page
                    item_per_page: item_per_page
                    sort: sort
                    desc: desc
                    filters:
                        name:
                            type: string
                        enabled:
                            field: enabled         # Not required if the filter name is equal to the field name
                            type: boolean          # The type in which the value of the filter will be casted
                sort:
                    delimiter: ','
                    attributes_availables: ['name', 'createdAt']

Step 4: Use the bundle is simple

The goal of this bundle is to paginate some Entity (ORM) or Document (MongoDB) class. You can use it in two ways.

  1. Use default pagination manager.
  2. Use custom pagination manager.

In Controllers

Initialize pagination

// Acme\DemoBundle\Controller\FooController.php

public function listAction(Request $request)
{
    / @var \Oka\PaginationBundle\Service\PaginationManager $pm */
    $pm = $this->get('oka_pagination.manager');
    
    // Use default pagination manager
    / @var \Oka\PaginationBundle\Util\PaginationResultSet $page */
    $page = $pm->paginate(Foo::class, $request, [], ['name' => 'ASC']);
    
    // Or use custom pagination manager
    // / @var \Oka\PaginationBundle\Util\PaginationResultSet $page */
    // $page = $pm->paginate('foo', $request, [], ['name' => 'ASC']);
    
    // parameters to template
    return $this->render('AcmeDemoBundle:Foo:list.html.twig', ['page' => $page]);
}

In Views (Twig)

{# total items count #}
<div class="count">
    {{ page.getFullyItems() }}
</div>

<table>
{# table body #}
{% for item in page.items %}
<tr {% if loop.index is odd %}class="color"{% endif %}>
    <td>{{ item.id }}</td>
    <td>{{ item.title }}</td>
</tr>
{% endfor %}
</table>

{# display navigation #}
<div class="navigation">
    {# Use the current pagination manager #}
    {{ paginate('foo_path' , {'query': 'query'}) }}
    
    {# Or use a specific pagination manager #}
    {# {{ paginate_foo('foo_path' , {'query': 'query'}) }} #}
</div>

Advanced Usage

// Acme\DemoBundle\Controller\FooController.php

public function listAction(Request $request)
{
    / @var \Oka\PaginationBundle\Service\PaginationManager $pm */
    $pm = $this->get('oka_pagination.manager');
    
    // Use default pagination manager
    / @var \Oka\PaginationBundle\Util\PaginationResultSet $page */
    $pm->createQuery('foo', $request, [], ['name' => 'ASC'])
       ->setCountItemsCallable(function(EntityRepository $er, array $criteria){
           // Here your code to return the number of elements
           // ...
       })
       ->setSelectItemsCallable(function(EntityRepository $er, array $criteria, array $orderBy, $limit, $offset){
           // Here your code to return the elements list
           // ...
       });
    
    / @var \Oka\PaginationBundle\Util\PaginationResultSet $page */
    $page = $pm->fetch();
    
    // parameters to template
    return $this->render('AcmeDemoBundle:Foo:list.html.twig', ['page' => $page]);
}

Details

OkaPaginationBundle

This bundle provides a flexible pagination system.

Latest Stable Version Total Downloads Latest Unstable Version License Monthly Downloads Daily Downloads SensioLabsInsight

Latest updates

For notes about latest changes please read CHANGELOG, for required changes in your code please read UPGRADE chapter of documentation.

Documentation

Read the Resources/doc/index.md.

Installation

All the installation instructions are located in the documentation.

Original Credits

License

This bundle is under the MIT license. See the complete license in the bundle.


  Files folder image Files (38)  
File Role Description
Files folder imagesrc (1 file, 8 directories)
Accessible without login Plain text file CHANGELOG.md Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (38)  /  src  
File Role Description
Files folder imageConverter (2 files, 3 directories)
Files folder imageDependencyInjection (2 files)
Files folder imageException (4 files)
Files folder imageResources (3 directories)
Files folder imageService (4 files)
Files folder imageTests (3 directories)
Files folder imageTwig (1 file)
Files folder imageUtil (4 files)
  Plain text file OkaPaginationBundle.php Class Class source

  Files folder image Files (38)  /  src  /  Converter  
File Role Description
Files folder imageDBAL (4 files)
Files folder imageMongodb (1 file)
Files folder imageORM (3 files)
  Plain text file AbstractQueryExprConverter.php Class Class source
  Plain text file QueryExprConverterInterface.php Class Class source

  Files folder image Files (38)  /  src  /  Converter  /  DBAL  
File Role Description
  Plain text file EqualQueryExprConverter.php Class Class source
  Plain text file LikeQueryExprConverter.php Class Class source
  Plain text file NotEqualQueryExprConverter.php Class Class source
  Plain text file NotLikeQueryExprConverter.php Class Class source

  Files folder image Files (38)  /  src  /  Converter  /  Mongodb  
File Role Description
  Plain text file RangeQueryExprConverter.php Class Class source

  Files folder image Files (38)  /  src  /  Converter  /  ORM  
File Role Description
  Plain text file IsNotNullQueryExprConverter.php Class Class source
  Plain text file IsNullQueryExprConverter.php Class Class source
  Plain text file RangeQueryExprConverter.php Class Class source

  Files folder image Files (38)  /  src  /  DependencyInjection  
File Role Description
  Plain text file Configuration.php Class Class source
  Plain text file OkaPaginationExtension.php Class Class source

  Files folder image Files (38)  /  src  /  Exception  
File Role Description
  Plain text file BadQueryExprException.php Class Class source
  Plain text file ObjectManagerNotSupportedException.php Class Class source
  Plain text file PaginationException.php Class Class source
  Plain text file SortAttributeNotAvailableException.php Class Class source

  Files folder image Files (38)  /  src  /  Resources  
File Role Description
Files folder imageconfig (1 file)
Files folder imagedoc (1 file)
Files folder imageviews (1 directory)

  Files folder image Files (38)  /  src  /  Resources  /  config  
File Role Description
  Accessible without login Plain text file services.yml Data Auxiliary data

  Files folder image Files (38)  /  src  /  Resources  /  doc  
File Role Description
  Accessible without login Plain text file index.md Doc. Documentation

  Files folder image Files (38)  /  src  /  Resources  /  views  
File Role Description
Files folder imagePagination (1 file)

  Files folder image Files (38)  /  src  /  Resources  /  views  /  Pagination  
File Role Description
  Accessible without login Plain text file paginate.html.twig Data Auxiliary data

  Files folder image Files (38)  /  src  /  Service  
File Role Description
  Plain text file PaginationManager.php Class Class source
  Plain text file PaginationManagerBag.php Class Class source
  Plain text file QueryBuilderHandler.php Class Class source
  Plain text file QueryBuilderManipulator.php Class Class source

  Files folder image Files (38)  /  src  /  Tests  
File Role Description
Files folder imageConverter (2 files, 1 directory)
Files folder imageService (1 file)
Files folder imageUtil (1 file)

  Files folder image Files (38)  /  src  /  Tests  /  Converter  
File Role Description
Files folder imageORM (1 file)
  Plain text file LikeQueryExprConvertertest.php Class Class source
  Plain text file NotLikeQueryExprConvertertest.php Class Class source

  Files folder image Files (38)  /  src  /  Tests  /  Converter  /  ORM  
File Role Description
  Plain text file RangeQueryExprConvertertest.php Class Class source

  Files folder image Files (38)  /  src  /  Tests  /  Service  
File Role Description
  Plain text file QueryBuilderManipulatorTest.php Class Class source

  Files folder image Files (38)  /  src  /  Tests  /  Util  
File Role Description
  Plain text file RequestParserTest.php Class Class source

  Files folder image Files (38)  /  src  /  Twig  
File Role Description
  Plain text file OkaPaginationExtension.php Class Class source

  Files folder image Files (38)  /  src  /  Util  
File Role Description
  Plain text file FilterUtil.php Class Class source
  Plain text file PaginationQuery.php Class Class source
  Plain text file PaginationResultSet.php Class Class source
  Plain text file RequestParser.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:34
This week:0
All time:11,026
This week:206Up