Developed with love by KnpLabs Hire us for your project!
223

WhiteOctoberPagerfantaBundle

by whiteoctober

Bundle to use Pagerfanta with Symfony2.

WhiteOctoberPagerfantaBundle

Build Status Scrutinizer Quality Score SensioLabsInsight

Bundle to use Pagerfanta with Symfony2.

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 Symfony2 master branch.

The bundle includes:

  • 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

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

2) Then add the WhiteOctoberPagerfantaBundle to your application kernel:

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

3) Configure and use things!

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

B) Rendering in Twig is shown below in the Rendering pagerfantas section.

C) Configuration is shown through this document

Making Bad Page Numbers Return a 404

Right now when the page is out of range or not a number, the server returns a 500 response. You can set the following parameter to show a 404 exception when the requested page is not valid instead.
It is set to "false" by defauly to provide backwards-compatibility (before it was 500).

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

Rendering pagerfantas

    {{ pagerfanta(my_pager, view_name, view_options) }}

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:

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

Twitter Bootstrap

The bundle also has TwitterBootstrapView.

For Bootstrap 2:

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

For Bootstrap 3:

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

Custom template

If you want to use a custom template, add another argument

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

With Options

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

See the Pagerfanta documentation for the list of the parameters.

Translate in your language

The bundle also offers two views to translate the default and the
twitter bootstrap views.

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

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

Adding Views

The views are added to the container with the pagerfanta.view tag:

XML

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

YAML

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.

For this you have to define views with the special view OptionableView:

services:
    pagerfanta.view.my_view_1:
        class: Pagerfanta\View\OptionableView
        arguments:
            - @pagerfanta.view.default
            - { proximity: 2, previous_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:

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

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

Configuration

It's possible to configure the default view for all rendering in your
configuration file:

white_october_pagerfanta:
    default_view: my_view_1

Basic CSS for the default view

The bundles comes with a basic css for the default view to be able to use a
good paginator faster. Of course you can change it, use another one or
create your own view.

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

More information

For more advanced documentation, check the Pagerfanta documentation.

Author

Pablo Díez - pablodip@gmail.com

License

Pagerfanta is licensed under the MIT License. See the LICENSE file for full
details.

Sponsors

WhiteOctober

Copyright (c) 2011 Pablo Díez

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
white_october_pagerfanta:
default_view: default
exceptions_strategy:
out_of_range_page: false
not_valid_current_page: false
  • Merge pull request #103 from EmanueleMinotto/master
    By pablodip, 2 years ago
  • fixed tests for travis-ci
    By EmanueleMinotto, 2 years ago
  • Merge pull request #102 from jpass/patch-1
    By pablodip, 2 years ago
  • fix whiteoctober/WhiteOctoberPagerfantaBundle#62
    By , 2 years ago
  • Merge pull request #101 from vendora/master
    By pablodip, 2 years ago
  • Fixed target language
    By , 2 years ago
  • Add Persian translation official language of Iran
    By aramalipoor, 2 years ago
  • Merge pull request #99 from weaverryan/patch-1
    By pablodip, 2 years ago
  • Updating README for easier Composer instructions
    By weaverryan, 2 years ago
  • Merge pull request #97 from PayteR/patch-1
    By pablodip, 2 years ago
  • Slovak translation
    By PayteR, 2 years ago
  • Merge pull request #91 from liverbool/master
    By pablodip, 2 years ago
  • Add support Thai language.
    By liverbool, 2 years ago
  • Merge pull request #89 from mitjade/master
    By pablodip, 3 years ago
  • target-language fix
    By mitjade, 3 years ago
  • slovenian translation
    By mitjade, 3 years ago
  • Merge pull request #88 from antistatique/master
    By pablodip, 3 years ago
  • [doc] Examples for twitter bootstrap view
    By gagarine, 3 years ago
  • Merge pull request #87 from Etheriq/master
    By pablodip, 3 years ago
  • Update .gitignore
    By , 3 years ago
  • Ukrainian translation added
    By Etheriq, 3 years ago
  • Merge pull request #84 from thecodeassassin/master
    By pablodip, 3 years ago
  • Fixed accidental commenting of assertion
    By Stephen Hoogendijk, 3 years ago
  • Added functional test for view with routeParams
    By Stephen Hoogendijk, 3 years ago
  • Merge pull request #82 from thecodeassassin/master
    By pablodip, 3 years ago
  • Fixed issue with reading routeParams from options
    By Stephen Hoogendijk, 3 years ago
  • Merge pull request #79 from oujesky/master
    By pablodip, 3 years ago
  • Merge pull request #60 from formapro-forks/out-range-exception-to-http-not-found
    By pablodip, 3 years ago
  • Merge pull request #3 from Skadabr/out-range-exception-to-http-not-found
    By makasim, 3 years ago
  • correct tests names
    By , 3 years ago