PHPackages                             kosinix/paginator - 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/paginator

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

kosinix/paginator
=================

A generic PHP class to split large data into smaller chunks for use in web apps

3.0.0(9y ago)1791MITPHPPHP &gt;=5.3.3

Since Oct 16Pushed 9y ago1 watchersCompare

[ Source](https://github.com/kosinix/paginator)[ Packagist](https://packagist.org/packages/kosinix/paginator)[ Docs](https://github.com/kosinix/paginator)[ RSS](/packages/kosinix-paginator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (4)Used By (0)

Paginator
=========

[](#paginator)

A generic PHP class to split large data into smaller chunks for use in web apps.

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

[](#requirements)

- PHP &gt;= 5.3.3

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/Paginator.php'; // Change this to the correct path
```

### Composer

[](#composer)

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

```
composer require kosinix/paginator: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)

Include the class and pass the required parameters

```
require_once 'src/Kosinix/Paginator.php';

$total = 23; // This will come from your app. Eg. do an SQL count: 'SELECT COUNT(*) AS `total` FROM user'
$current_page = 2; // This will come from your app. Eg. $current_page = $_GET['page'];
$per_page = 10; // This will also come from your app.

$paginator = new \Kosinix\Paginator($total, $current_page, $per_page);

$sql = sprintf('SELECT * FROM users LIMIT %d,%d', $paginator->getStartIndex(), $paginator->getPerPage());

// Run sql query here
```

The constructor accepts the following parameters:

- **total** - The total number of records.
- **current\_page** - The current page to display. Defaults to 1.
- **per\_page** - The number of records in a page. Defaults to 10.

Terms are best explained by this image

[![alt tag](docs/info.jpg)](docs/info.jpg)

Silex Service Provider
----------------------

[](#silex-service-provider)

You can also create a service provider for paginator for use in Silex:

```
// PaginatorServiceProvider.php

use Silex\Application;
use Silex\ServiceProviderInterface;
use Kosinix\Paginator;

class PaginatorServiceProvider implements ServiceProviderInterface {

    public function register(Application $app) {
        $app['paginator.per_page'] = isset($app['paginator.per_page']) ? (int)$app['paginator.per_page'] : 10;
        $app['paginator'] = $app->protect(
            function ($total, $page, $per_page=null) use ($app) {
                if(null === $per_page){
                    $per_page = $app['paginator.per_page'];
                }
                return new Paginator($total, $page, $per_page);
            }
        );
    }

    public function boot(Application $app) {

    }
}
```

Then in your app:

```
// Paginator
$app->register(new PaginatorServiceProvider());
```

In your controller:

```
$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); // $page would come from your web app
```

Test
----

[](#test)

- Go to the project folder and run phpunit in the command line.
- You need to have phpunit installed globally.

License
-------

[](#license)

- MIT

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

Established project with proven stability

 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.

###  Release Activity

Cadence

Every ~375 days

Total

3

Last Release

3483d ago

Major Versions

1.0.0 → 2.0.02015-05-26

2.0.0 → 3.0.02016-11-04

### 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 (1 commits)")

---

Tags

paginator

### Embed Badge

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

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

###  Alternatives

[nette/utils

🛠 Nette Utils: lightweight utilities for string &amp; array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.

2.1k394.3M1.5k](/packages/nette-utils)[knplabs/knp-components

Knplabs component library

77443.6M46](/packages/knplabs-knp-components)[coffeecode/paginator

Paginator is simple and is ready to generate results navigation in your application

59658.1k1](/packages/coffeecode-paginator)[beberlei/porpaginas

Library that generically solves several pagination issues with DAO/repository abstractions.

163612.6k11](/packages/beberlei-porpaginas)[laminas/laminas-paginator

Paginate collections of data from arbitrary sources

245.7M84](/packages/laminas-laminas-paginator)[stefangabos/zebra_pagination

A generic, Twitter Bootstrap compatible, PHP pagination library that automatically generates navigation links

11122.9k](/packages/stefangabos-zebra-pagination)

PHPackages © 2026

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