2017 © Pedro Peláez
 

library silex-pagerfanta-provider

Silex ServiceProvider for Pagerfanta Library

image

sinasalek/silex-pagerfanta-provider

Silex ServiceProvider for Pagerfanta Library

  • Sunday, June 19, 2016
  • by sinasalek
  • Repository
  • 1 Watchers
  • 0 Stars
  • 69 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 16 Forks
  • 0 Open issues
  • 4 Versions
  • 11 % Grown

The README.md

PagerfantaServiceProvider

Provider to use Pagerfanta with Silex, (*1)

This Provider is based on WhiteOctoberPagerfantaBundle and includes: * Twig function to render pagerfantas with views and options. * Way to use easily views., (*2)

Install

You have to add to your composer.json file:, (*3)

"franmomu/silex-pagerfanta-provider": "1.0.*@dev"

or if you use Symfony2.2 components:, (*4)

"franmomu/silex-pagerfanta-provider": "dev-master"

Registering

$app->register(new FranMoreno\Silex\Provider\PagerfantaServiceProvider());

Parameters

This are the default parameters:, (*5)

$app['pagerfanta.view.options'] = array(
    'routeName'        => null,
    'routeParams'      => array(),
    'pageParameter'    => '[page]',
    'proximity'        => 3,
    'next_message'     => '»',
    'previous_message' => '«',
    'default_view'     => 'default'
);

Rendering pagination

The Twig Extension provides this function:, (*6)

{{ 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., (*7)

{{ pagerfanta(my_pager) }}

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

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

With Options, (*9)

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

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

Adding a custom template

You can use the CSS classes provided with DefaultView, but if you want to create a Custom View, you have to implement Pagerfanta\View\ViewInterface, then add the View to the Factory:, (*11)

$app['pagerfanta.view_factory'] = $app->share($app->extend('pagerfanta.view_factory', function($viewFactory, $app) {
    $customView = new \Foo\Bar\View\CustomView();
    $viewFactory->add(array(
        'my_view' => $customView
    ));

    return $viewFactory;
}));

And if you want set as default view:, (*12)

$app['pagerfanta.view.options'] = array(
    'default_view'  => 'my_view'
);

Use in controllers

use Pagerfanta\Pagerfanta;
use Pagerfanta\Adapter\ArrayAdapter;

$app->get('/index', function (Request $request) use ($app) {

    $results = $app['some.service']->getResults();

    $adapter = new ArrayAdapter($results);
    $pagerfanta = new Pagerfanta($adapter);
    $pagerfanta->setMaxPerPage(10);
    $pagerfanta->setCurrentPage($request->query->get('page', 1));

    return $app['twig']->render('index.html', array(
        'my_pager' => $pagerfanta
    ));
})

The Versions

19/06 2016

dev-master

9999999-dev https://github.com/sinasalek/silex-pagerfanta-provider

Silex ServiceProvider for Pagerfanta Library

  Sources   Download

MIT

The Requires

 

silex service provider pagerfanta

07/04 2015

v1.1.0

1.1.0.0 https://github.com/franmomu/silex-pagerfanta-provider

Silex ServiceProvider for Pagerfanta Library

  Sources   Download

MIT

The Requires

 

silex service provider pagerfanta

27/03 2013

1.0.x-dev

1.0.9999999.9999999-dev https://github.com/franmomu/silex-pagerfanta-provider

Silex ServiceProvider for Pagerfanta Library

  Sources   Download

MIT

The Requires

 

silex service provider pagerfanta

27/03 2013

v1.0.0

1.0.0.0 https://github.com/franmomu/silex-pagerfanta-provider

Silex ServiceProvider for Pagerfanta Library

  Sources   Download

MIT

The Requires

 

silex service provider pagerfanta