2017 © Pedro PelĂĄez
 

symfony-bundle pagerfanta-bundle

Bundle to use Pagerfanta with Symfony2

image

white-october/pagerfanta-bundle

Bundle to use Pagerfanta with Symfony2

  • Wednesday, June 20, 2018
  • by pablodip
  • Repository
  • 34 Watchers
  • 338 Stars
  • 3,649,349 Installations
  • PHP
  • 138 Dependents
  • 11 Suggesters
  • 88 Forks
  • 15 Open issues
  • 24 Versions
  • 7 % Grown

The README.md

This project is no longer maintained. If you are using it with Symfony 3.4, 4.4 or 5, you may want to use this fork instead., (*1)

WhiteOctoberPagerfantaBundle

Build Status Scrutinizer Quality Score SensioLabsInsight, (*2)

Bundle to use Pagerfanta with Symfony., (*3)

Note: If you are using a 2.0.x release of Symfony2, please use the symfony2.0 branch of this bundle. The master branch of this bundle tracks the Symfony master branch., (*4)

The bundle includes:, (*5)

  • Twig function to render pagerfantas with views and options.
  • Way to use easily views.
  • Way to reuse options in views.
  • Basic CSS for the DefaultView.

Installation

1) Use Composer to download the library, (*6)

php composer.phar require white-october/pagerfanta-bundle

2) Then add the WhiteOctoberPagerfantaBundle to your application:, (*7)

In Symfony < 4:, (*8)

// app/AppKernel.php
public function registerBundles()
{
    return array(
        // ...
        new WhiteOctober\PagerfantaBundle\WhiteOctoberPagerfantaBundle(),
        // ...
    );
}

In Symfony 4 with Symfony Flex this will be done automatically for you., (*9)

3) Configure and use things!, (*10)

A) Creating a Pager is shown on the Pagerfanta documentation. If you're using the Doctrine ORM, you'll want to use the DoctrineORMAdapter, (*11)

B) Rendering in Twig is shown below in the Rendering Pagerfantas section., (*12)

C) Configuration is shown through this document, (*13)

Rendering Pagerfantas

First, you'll need to pass an instance of Pagerfanta as a parameter into your template. For example:, (*14)

$adapter = new DoctrineORMAdapter($queryBuilder);
$pagerfanta = new Pagerfanta($adapter);
return $this->render('@YourApp/Main/example.html.twig', [
    'my_pager' => $pagerfanta,
]);

You then call the the Pagerfanta Twig extension, passing in the Pagerfanta instance. The routes are generated automatically for the current route using the variable "page" to propagate the page number. By default, the bundle uses the DefaultView with the default name. The default syntax is:, (*15)

<div class="pagerfanta">
    {{ pagerfanta(my_pager) }}
</div>

By default, the "page" variable is also added for the link to the first page. To disable the generation of ?page=1 in the url, simply set the omitFirstPage option to true when calling the pagerfanta twig function:, (*16)

{{ pagerfanta(my_pager, 'default', { 'omitFirstPage': true}) }}

You can omit template parameter to make function call shorter, default template will be used:, (*17)

{{ pagerfanta(my_pager, { 'omitFirstPage': true }) }}

If you have multiple pagers on one page, you'll need to change the name of the page parameter. Here's an example:, (*18)

<div class="pagerfanta">
    {{ pagerfanta(my_other_pager, 'default', {'pageParameter': '[page_other]'}) }}
</div>

Note the square brackets around page_other; this won't work without them., (*19)

Twitter Bootstrap

The bundle also has a Twitter Bootstrap view., (*20)

For Bootstrap 2:, (*21)

<div class="pagerfanta">
    {{ pagerfanta(my_pager, 'twitter_bootstrap') }}
</div>

For Bootstrap 3:, (*22)

<div class="pagerfanta">
    {{ pagerfanta(my_pager, 'twitter_bootstrap3') }}
</div>

For Bootstrap 4:, (*23)

<div class="pagerfanta">
    {{ pagerfanta(my_pager, 'twitter_bootstrap4') }}
</div>

Custom template

If you want to use a custom template, add another argument:, (*24)

<div class="pagerfanta">
    {{ pagerfanta(my_pager, 'my_template') }}
</div>

With options:, (*25)

{{ pagerfanta(my_pager, 'default', { 'proximity': 2}) }}

See the Pagerfanta documentation for the list of possible parameters., (*26)

Rendering the page of items itself

The items can be retrieved using currentPageResults. For example:, (*27)

{% for item in my_pager.currentPageResults %}
    <ul>
        <li>{{ item.id }}</li>
    </ul>
{% endfor %}

Translate in your language

The bundle also offers two views to translate the default and the twitter bootstrap views., (*28)

{{ pagerfanta(my_pager, 'default_translated') }}

{{ pagerfanta(my_pager, 'twitter_bootstrap_translated') }}

Adding Views

The views are added to the container with the pagerfanta.view tag:, (*29)

XML, (*30)

<service id="pagerfanta.view.default" class="Pagerfanta\View\DefaultView" public="false">
    <tag name="pagerfanta.view" alias="default" />
</service>

YAML, (*31)

services:
    pagerfanta.view.default:
        class: Pagerfanta\View\DefaultView
        public: false
        tags: [{ name: pagerfanta.view, alias: default }]

Reusing Options

Sometimes you want to reuse options of a view in your project, and you don't want to write them all the times you render a view, or you can have different configurations for a view and you want to save them in a place to be able to change them easily., (*32)

For this you have to define views with the special view OptionableView:, (*33)

services:
    pagerfanta.view.my_view_1:
        class: Pagerfanta\View\OptionableView
        arguments:
            - @pagerfanta.view.default
            - { proximity: 2, prev_message: Anterior, next_message: Siguiente }
        public: false
        tags: [{ name: pagerfanta.view, alias: my_view_1 }]
    pagerfanta.view.my_view_2:
        class: Pagerfanta\View\OptionableView
        arguments:
            - @pagerfanta.view.default
            - { proximity: 5 }
        public: false
        tags: [{ name: pagerfanta.view, alias: my_view_2 }]

And using then:, (*34)

{{ pagerfanta(my_pager, 'my_view_1') }}
{{ pagerfanta(my_pager, 'my_view_2') }}

The easiest way to render pagerfantas (or paginators!) ;), (*35)

Basic CSS for the default view

The bundles comes with basic CSS for the default view so you can get started with a good paginator faster. Of course you can change it, use another one or create your own view., (*36)

<link rel="stylesheet" href="{{ asset('bundles/whiteoctoberpagerfanta/css/pagerfantaDefault.css') }}" type="text/css" media="all" />

Configuration

It's possible to configure the default view for all rendering in your configuration file:, (*37)

white_october_pagerfanta:
    default_view: my_view_1

Making bad page numbers return a HTTP 500

Right now when the page is out of range or not a number, the server returns a 404 response by default. You can set the following parameters to different than default value to_http_not_found (ie. null) to show a 500 exception when the requested page is not valid instead., (*38)

// app/config/config.yml
white_october_pagerfanta:
    exceptions_strategy:
        out_of_range_page:        ~
        not_valid_current_page:   ~

More information

For more advanced documentation, check the Pagerfanta documentation., (*39)

Contributing

We welcome contributions to this project, including pull requests and issues (and discussions on existing issues)., (*40)

If you'd like to contribute code but aren't sure what, the issues list is a good place to start. If you're a first-time code contributor, you may find Github's guide to forking projects helpful., (*41)

All contributors (whether contributing code, involved in issue discussions, or involved in any other way) must abide by our code of conduct., (*42)

Acknowledgements

Pablo DĂ­ez (pablodip@gmail.com) for most of the work on the first versions of this bundle., (*43)

This project was originally located at https://github.com/whiteoctober/WhiteOctoberPagerfantaBundle., (*44)

License

Pagerfanta is licensed under the MIT License. See the LICENSE file for full details., (*45)

The Versions

14/06 2018

dev-fix/document-bundles.php

dev-fix/document-bundles.php

Bundle to use Pagerfanta with Symfony2

  Sources   Download

MIT

The Requires

 

The Development Requires

page paging

21/07 2017

2.1.x-dev

2.1.9999999.9999999-dev

Bundle to use Pagerfanta with Symfony2

  Sources   Download

MIT

The Requires

 

page paging

14/02 2017
16/03 2016

dev-fix_travis_php53_memory_limit

dev-fix_travis_php53_memory_limit

Bundle to use Pagerfanta with Symfony2

  Sources   Download

MIT

The Requires

 

The Development Requires

page paging

16/03 2016

dev-omit_first_page_false_by_default

dev-omit_first_page_false_by_default

Bundle to use Pagerfanta with Symfony2

  Sources   Download

MIT

The Requires

 

The Development Requires

page paging

01/09 2015
29/04 2015
07/01 2014
04/01 2014

dev-pagerfanta_twig_extension_without_container

dev-pagerfanta_twig_extension_without_container

Bundle to use Pagerfanta with Symfony2

  Sources   Download

MIT

The Requires

 

The Development Requires

page paging

09/12 2013
17/07 2013

dev-symfony2.0

dev-symfony2.0

Bundle to use Pagerfanta with Symfony2

  Sources   Download

MIT

The Requires

 

page paging

06/06 2013

v1.0.0

1.0.0.0

Bundle to use Pagerfanta with Symfony2

  Sources   Download

MIT

The Requires

 

page paging