PHPackages                             kosinix/pagination-silex - 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. kosinix/pagination-silex

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

kosinix/pagination-silex
========================

Adds pagination functionality to a Silex app. Used in tandem with Paginator.

1137PHP

Since Nov 4Pushed 9y ago1 watchersCompare

[ Source](https://github.com/kosinix/pagination-silex)[ Packagist](https://packagist.org/packages/kosinix/pagination-silex)[ RSS](/packages/kosinix-pagination-silex/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependenciesVersions (1)Used By (0)

Pagination Silex
================

[](#pagination-silex)

Adds pagination functionality to a Silex app. Used in tandem with Paginator.

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

[](#requirements)

- PHP &gt;= 5.3.3
- [Kosinix\\Paginator](https://github.com/kosinix/paginator) (Install it independently)
- \\Symfony\\Component\\Routing\\Generator\\UrlGenerator (Included with Silex)

Installation
------------

[](#installation)

### Manual

[](#manual)

- Download the zip file from the Github repository.
- Unpack the zip file and include the files in your project.
- Include the class in /src/:

```
require_once '/path/to/src/Kosinix/Pagination.php'; // Change this to the correct path
```

### Composer

[](#composer)

Inside your project directory, open the command line and type:

```
composer require kosinix/pagination:dev-master --prefer-dist
```

Include the autoload.php found in vendor/:

```
require_once '/path/to/vendor/autoload.php'; // Change this to the correct path
```

Usage
-----

[](#usage)

Example, inside a Controller Provider:

```
$controllers->get('/products/{page}/{sort_by}/{sorting}', function (Request $request, Application $app, $page, $sort_by, $sorting) {
    $sql = 'SELECT COUNT(*) AS `total` FROM product';
    $count = $app['db']->fetchAssoc($sql);
    $count = (int) $count['total'];

    /** @var \Kosinix\Paginator $paginator */
    $paginator =  $app['paginator']($count, $page);

    $sql = sprintf('SELECT
        *
    FROM
        product
    WHERE
        1=1
    ORDER BY %s %s
    LIMIT %d,%d',
        $sort_by, strtoupper($sorting), $paginator->getStartIndex(), $paginator->getPerPage());

    $products = $app['db']->fetchAll($sql);

    $pagination = new Pagination($paginator, $app['url_generator'], 'admin/products', $sort_by, $sorting);

    return $app['twig']->render('admin/products/index.twig', array(
        'products' => $products,
        'pagination' => $pagination
    ));
})->value('page', 1)
->value('sort_by', 'created')
->value('sorting', 'asc')
->assert('page', '\d+') // Numbers only
->assert('sort_by','[a-zA-Z_]+') // Match a-z, A-Z, and "_"
->assert('sorting','(\basc\b)|(\bdesc\b)') // Match "asc" or "desc"
->bind('admin/products');
```

Add pagination.twig in your views:

```
{% if pagination.isNeeded() %}

	&laquo;&laquo; First
	{% if pagination.isPreviousPage() %}
		&laquo; Prev
	{% endif %}
	{% for page in range(pagination.getPaginator().shortPageStart(), pagination.getPaginator().shortPageEnd()) %}
		{% if pagination.getPaginator().getCurrentPage() == page %}
			{{page}}
		{% else %}
			{{page}}
		{% endif %}
	{% endfor %}
	{% if pagination.isNextPage() %}
		Next &raquo;
	{% endif %}
	Last &raquo;&raquo;

{% endif %}
```

And use it in your view file:

```
Products
{% if products %}

            ID
            Name
            Quantity
            Description
            Date

        {% for product in products %}

                {{ product.id }}
                {{ product.name }}
                {{ product.quantity }}
                {{ product.description }}
                {{ product.created|date("F d, Y")  }}

        {% endfor %}

        {% include 'pagination.twig' %}

{% else %}
    No products found.
{% endif %}
```

Thats it.

License
-------

[](#license)

- MIT

###  Health Score

22

—

LowBetter than 21% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/04bc94fd10d5977199a72f4d66f7de7d0c47aa10cf214f7160adc64b42e44d64?d=identicon)[kosinix](/maintainers/kosinix)

---

Top Contributors

[![kosinix](https://avatars.githubusercontent.com/u/1096465?v=4)](https://github.com/kosinix "kosinix (6 commits)")

### Embed Badge

![Health badge](/badges/kosinix-pagination-silex/health.svg)

```
[![Health](https://phpackages.com/badges/kosinix-pagination-silex/health.svg)](https://phpackages.com/packages/kosinix-pagination-silex)
```

###  Alternatives

[cmixin/enhanced-period

Carbon mixin to convert `Carbon\\CarbonPeriod` to `Spatie\\Period\\Period` and vice versa

1967.9k2](/packages/cmixin-enhanced-period)

PHPackages © 2026

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