PHPackages                             ttskch/pagination-service-provider - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. ttskch/pagination-service-provider

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

ttskch/pagination-service-provider
==================================

pagination service provider for the Silex microframework.

4.0.1(8y ago)56.2k2MITPHPPHP &gt;=5.5.9

Since Jun 4Pushed 8y ago2 watchersCompare

[ Source](https://github.com/ttskch/PaginationServiceProvider)[ Packagist](https://packagist.org/packages/ttskch/pagination-service-provider)[ Docs](https://github.com/ttskch/PaginationServiceProvider)[ RSS](/packages/ttskch-pagination-service-provider/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (10)Versions (7)Used By (0)Security (1)

PaginationServiceProvider
=========================

[](#paginationserviceprovider)

[![Build Status](https://camo.githubusercontent.com/c10526018bb8c95cd7740a9ed454fe684992d5ccd51d38cfb2d80828a8a6443d/68747470733a2f2f7472617669732d63692e6f72672f7474736b63682f506167696e6174696f6e5365727669636550726f76696465722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/ttskch/PaginationServiceProvider)[![Latest Stable Version](https://camo.githubusercontent.com/aa1d92c461d7d429d8abc7bb0966e367c6d1de802084c2b3cde1250d8001c218/68747470733a2f2f706f7365722e707567782e6f72672f7474736b63682f706167696e6174696f6e2d736572766963652d70726f76696465722f76657273696f6e2e737667)](https://packagist.org/packages/ttskch/pagination-service-provider)[![Total Downloads](https://camo.githubusercontent.com/1560cc2733689bbe6291614858cd912ab382f46ca313e63063b042098fe486bf/68747470733a2f2f706f7365722e707567782e6f72672f7474736b63682f706167696e6174696f6e2d736572766963652d70726f76696465722f646f776e6c6f6164732e737667)](https://packagist.org/packages/ttskch/pagination-service-provider)

This service provider allows you to use [KnpPaginatorBundle](https://github.com/KnpLabs/KnpPaginatorBundle) in your Silex application.

Requirements
------------

[](#requirements)

- 3.x: PHP 5.5.9+
- 1.x: PHP 5.3+

Getting Started
---------------

[](#getting-started)

### For Silex 2.x

[](#for-silex-2x)

```
$ composer require ttskch/pagination-service-provider
```

### For Silex 1.x

[](#for-silex-1x)

```
$ composer require ttskch/pagination-service-provider:~1.0
```

And enable this service provider in your application:

```
$app->register(new Ttskch\Silex\Provider\PaginationServiceProvider());
```

If you need, you can configure default query parameter names and templates as below (almost same as [origin](https://github.com/KnpLabs/KnpPaginatorBundle#configuration-example)):

```
$app['knp_paginator.options'] = array(
    'default_options' => array(
        'sort_field_name' => 'sort',
        'sort_direction_name' => 'direction',
        'filter_field_name' => 'filterField',
        'filter_value_name' => 'filterValue',
        'page_name' => 'page',
        'distinct' => true,
    ),
    'template' => array(
        'pagination' => '@knp_paginator_bundle/sliding.html.twig',
        'filtration' => '@knp_paginator_bundle/filtration.html.twig',
        'sortable' => '@knp_paginator_bundle/sortable_link.html.twig',
    ),
    'page_range' => 5,
);
```

Then you can create pagination instance and render it in view:

```
// in your controller.

$pagination = $app['knp_paginator']->paginate($someData);

return $app['twig']->render('index.html.twig', array(
    'pagination' => $pagination,
));
```

```
{# in your twig template #}

{{ knp_pagination_render(pagination) }}
```

Usage
-----

[](#usage)

KnpPaginatorBundle can paginate [many things](https://github.com/KnpLabs/KnpPaginatorBundle#controller). But in Silex application we may use for:

- Array
- Doctrine\\DBALQueryBuilder

However KnpPaginatorBundle doesn't sort or filter these data automatically via request query parameter. If you want to sort or filter these data you should do by hand.

### Sort or filter array

[](#sort-or-filter-array)

When you want to sort or filter simple two-dimensional array, you can use [Cake\\Utility\\Hash](https://github.com/cakephp/utility/blob/master/Hash.php) (autoloaded) like as below:

```
// in your controller.

$array = /* some two dimensional array */;

$sort = $request->get('sort');
$direction = $request->get('direction', 'asc');
$filterField = $request->get('filterField');
$filterValue = $request->get('filterValue');

$array = Hash::extract($array, "{n}[{$filterField}=/{$filterValue}/]");
$array = Hash::sort($array, "{n}.{$sort}", $direction);

$pagination = $app['knp_paginator']->paginate($array); // You can get filtered and sorted pagination object.
```

See the [official document](http://book.cakephp.org/2.0/en/core-utility-libraries/hash.html) for more information of usage of Hash class.

### Sort or filter Doctrine\\DBALQueryBuilder

[](#sort-or-filter-doctrinedbalquerybuilder)

When you use Doctrine\\DBALQueryBuilder you can sort or filter by SQL clauses like as below:

```
// in your controller.

$sort = $request->get('sort');
$direction = $request->get('direction', 'asc') === 'asc' ? 'asc' : 'desc';
$filterField = $request->get('filterField');
$filterValue = $request->get('filterValue');

$qb = $app['db']->createQueryBuilder()
    ->select('t.*')
    ->from('table', 't')
    ->where("{$app['db']->quoteIdentifier($filterField)} like {$app['db']->quote('%' . $filterValue . '%')}")
    ->orderBy($app['db']->quoteIdentifier($sort), $direction)
;

$pagination = $app['knp_paginator']->paginate($qb);
```

Demo
----

[](#demo)

You can see demo code [here](demo/index.php). You also can run demo easily on your local by following command.

```
$ git clone git@github.com:ttskch/PaginationServiceProvider.git
$ cd PaginationServiceProvider
$ composer install
$ composer demo
```

Now you see demo on  like below.

[![image](https://cloud.githubusercontent.com/assets/4360663/25220829/fa640a40-25ed-11e7-847b-98434a786610.png)](https://cloud.githubusercontent.com/assets/4360663/25220829/fa640a40-25ed-11e7-847b-98434a786610.png)

Additional features
-------------------

[](#additional-features)

This service provider also provides bootstrap3-based beautiful pagination and filtration templates. You can use it as below:

```
$app['knp_paginator.options'] = array(
    'template' => array(
        'pagination' => '@ttskch_silex_pagination/pagination-bootstrap3.html.twig',
        'filtration' => '@ttskch_silex_pagination/filtration-bootstrap3.html.twig',
    ),
);
```

When you use the `pagination-bootstrap3.html.twig` template, you can configure the list of `Items per page` selector.

```
$app['knp_paginator.limits'] = array(10, 25, 50, 100, 200, 500),
```

You also can define translations for some labels in the `messages` domain.

```
$app['translator.domains'] = array(
    'messages' => array(
        'ja' => array(
            'Previous' => '前へ',
            'Next' => '次へ',
        ),
    ),
);
```

```
$app['translator.domains'] = array(
    'messages' => array(
        'ja' => array(
            'Items per page' => '1ページの件数',
            'Filter' => '絞り込み',
        ),
    ),
);
```

Note
----

[](#note)

This service provider depends on `TwigServiceProvider` and `TranslationServiceProvider`. Please register them before register `PaginationServiceProvider`.

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 50% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~150 days

Recently: every ~173 days

Total

6

Last Release

2924d ago

Major Versions

1.0.0 → 2.0.02016-08-02

2.0.0 → 3.0.02016-09-23

3.1.0 → 4.0.02017-05-08

PHP version history (2 changes)1.0.0PHP &gt;=5.3.3

2.0.0PHP &gt;=5.5.9

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4360663?v=4)[Takashi Kanemoto](/maintainers/ttskch)[@ttskch](https://github.com/ttskch)

---

Top Contributors

[![sergiors](https://avatars.githubusercontent.com/u/2046276?v=4)](https://github.com/sergiors "sergiors (7 commits)")[![ttskch](https://avatars.githubusercontent.com/u/4360663?v=4)](https://github.com/ttskch "ttskch (6 commits)")[![ruby232](https://avatars.githubusercontent.com/u/6253680?v=4)](https://github.com/ruby232 "ruby232 (1 commits)")

---

Tags

pagerpaginatorpaginationsilex

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ttskch-pagination-service-provider/health.svg)

```
[![Health](https://phpackages.com/badges/ttskch-pagination-service-provider/health.svg)](https://phpackages.com/packages/ttskch-pagination-service-provider)
```

###  Alternatives

[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k17.5M378](/packages/easycorp-easyadmin-bundle)[pimcore/pimcore

Content &amp; Product Management Framework (CMS/PIM/E-Commerce)

3.8k3.8M464](/packages/pimcore-pimcore)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.4M196](/packages/sulu-sulu)[open-dxp/opendxp

Content &amp; Product Management Framework (CMS/PIM)

9417.2k55](/packages/open-dxp-opendxp)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

585.4M524](/packages/shopware-core)[chameleon-system/chameleon-base

The Chameleon System core.

1027.9k4](/packages/chameleon-system-chameleon-base)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
