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

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

rayne/pagination
================

Pagination library without dependencies.

844PHP

Since Jul 22Pushed 7y ago1 watchersCompare

[ Source](https://github.com/Rayne/pagination)[ Packagist](https://packagist.org/packages/rayne/pagination)[ RSS](/packages/rayne-pagination/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (1)Used By (0)

Rayne\\Pagination
=================

[](#raynepagination)

Pagination library without dependencies.

Contents
--------

[](#contents)

- [Installation](#installation)
- [Features](#features)
- [Usage](#usage)
- [Examples](#examples)
- [Tests](#tests)

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

[](#installation)

It's recommended to use the dependency manager [Composer](https://getcomposer.org/download)to install `rayne/pagination`.

```
composer require rayne/pagination
```

Features
--------

[](#features)

- Implementation of the [Search Pagination Pattern](https://web.archive.org/web/20160407044536/https://developer.yahoo.com/ypatterns/navigation/pagination/search.html)defined by Yahoo

    - One or zero indexed pages
    - Extracts safe page numbers from arbitrary user inputs, e.g. first or last page on invalid input or when being out of bounds
- Implementation of the [Filter Pagination Pattern](https://web.archive.org/web/20150905182227/https://developer.yahoo.com/ypatterns/navigation/alphafilterlinks.html)defined by Yahoo

    (This pattern is currently not officially supported but the code is ready for playing around)
- No dependencies (except the ones for testing)
- Framework-agnostic

    - No markup (but Bootstrap examples in `/examples`)
    - No template engine (but Twig examples in `/examples`)
    - No database backend (but offset and limit provided)
    - No URL builder

Usage
-----

[](#usage)

### SearchPagination

[](#searchpagination)

1. Retrieve item count `$totalItems`
2. Let `Rayne\Pagination` calculate the offset

    ```
    $pagination = new SearchPagination(
        $totalItems,
        $itemsPerPage,
        $currentPage,
        $pagePadding = 4,
        $isZeroBased = false
    );
    ```
3. Verify `$currentPage` with `$pagination->isOnValidPage()`or retrieve the requested items with the help of `$pagination->getItemOffset()`and `$pagination->getItemLimit()`
4. Render results and controls with the help of `$pagination`or `$pagination->toArray()`and the example templates in the `/examples` directory

Read the [Examples](#examples) section for examples and ideas.

### SearchPaginationFactory

[](#searchpaginationfactory)

Instead of creating the `SearchPaginationInterface` implementation by hand a configurable factory can be used to provide the pagination as a service.

1. Either create a new factory (useful when working with a DI system) …

    ```
    $factory = new SearchPaginationFactory;
    ```

    … or initialize/fetch the global one

    ```
    $factory = SearchPaginationFactory::instance();
    ```

    The defaults are: one-indexed pages, `20` items per page and a page padding of `4`.
2. Configure the factory (or skip this step)

    ```
    $factory->setIsZeroBased(true);
    $factory->setItemsPerPage(25);
    $factory->setPagePadding(2);
    ```
3. Build a new `SearchPagination` object

    ```
    $totalItems = 123;
    $currentPage = 2;
    $pagination = $factory->build($totalItems, $currentPage);
    ```

### FilterPagination

[](#filterpagination)

The filter pagination pattern is not officially supported but feel free to play around with the following classes:

```
Rayne\Pagination\Filter\FilterPage
Rayne\Pagination\Filter\FilterPages
Rayne\Pagination\Filter\FilterPagination
```

Examples
--------

[](#examples)

The following examples are part of the `/examples` directory.

- Complete example (`/examples/index.php`)
- Simple (highlights current page) and advanced (highlights current page, hides redundant pagination controls) examples

    - PHP snippets (`/examples/PHP`)
    - [Twig](http://twig.sensiolabs.org) macros (`/examples/Twig`)
- The Twig macros are [Bootstrap Framework](http://getbootstrap.com) compatible

Tests
-----

[](#tests)

1. Clone the repository

    ```
    git clone https://github.com/rayne/pagination.git
    ```
2. Install the development dependencies

    ```
    composer install --dev
    ```
3. Run the tests

    ```
    composer test
    ```

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity40

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/3c8280f00784624f044fa15aa869fd0a3958b0ade356a01297eff1f6240332e2?d=identicon)[Rayne](/maintainers/Rayne)

---

Top Contributors

[![Rayne](https://avatars.githubusercontent.com/u/1098733?v=4)](https://github.com/Rayne "Rayne (20 commits)")

---

Tags

composer-libraryfilter-paginationpaginationphp-librarysearch-pagination

### Embed Badge

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

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

###  Alternatives

[aferrandini/urlizer

Library for urlizer

24768.2k8](/packages/aferrandini-urlizer)[coderevolutionplugins/gpt-3-encoder-php

PHP BPE Text Encoder/Decoder for GPT-2 / GPT-3

10046.1k](/packages/coderevolutionplugins-gpt-3-encoder-php)[cjstroud/classnames-php

A simple PHP utility for conditionally joining classNames together

20166.9k1](/packages/cjstroud-classnames-php)

PHPackages © 2026

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