PHPackages                             solophp/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. [HTTP &amp; Networking](/categories/http)
4. /
5. solophp/paginator

ActiveLibrary[HTTP &amp; Networking](/categories/http)

solophp/paginator
=================

PHP pagination package

v2.1.0(9mo ago)0106MITPHPPHP &gt;=8.2

Since Jul 13Pushed 9mo ago1 watchersCompare

[ Source](https://github.com/SoloPHP/Paginator)[ Packagist](https://packagist.org/packages/solophp/paginator)[ RSS](/packages/solophp-paginator/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (6)Dependencies (2)Versions (7)Used By (0)

PHP Paginator
=============

[](#php-paginator)

[![Latest Version on Packagist](https://camo.githubusercontent.com/c0a7e2f068f7d2f99534f2153e444379276040d68a333e5849b3c0fd8ab9dbcf/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f736f6c6f7068702f706167696e61746f722e737667)](https://packagist.org/packages/solophp/paginator)[![License](https://camo.githubusercontent.com/2b11a604c609cb44e37f5eae921bf2da9d3bba975b093716fdb39eff5216206f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f736f6c6f7068702f706167696e61746f722e737667)](https://opensource.org/licenses/MIT)[![PHP Version](https://camo.githubusercontent.com/47120d642fdf555c4aef5d1ecd813038c55b6d33643d679954fca2183e683653/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f736f6c6f7068702f706167696e61746f722e737667)](https://php.net)

A lightweight, framework-agnostic pagination package for PHP 8.2+.

Features
--------

[](#features)

- Zero dependencies
- Framework agnostic
- Configurable items per page
- Maintains all query parameters in URLs
- SEO-friendly pagination links
- Ellipsis support for long page lists
- Static interface
- Pre-calculated pagination support

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

[](#requirements)

- PHP 8.2 or higher

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

[](#installation)

You can install the package via composer:

```
composer require solophp/paginator
```

Usage
-----

[](#usage)

```
use Solo\Paginator\Paginator;

public static function paginate(
    array $queryParams,
    int $totalItems,
    array $limitOptions = [10, 25, 50, 100]
): PaginationResult
```

Parameters:

- `$queryParams` - Array of query parameters (typically `$_GET` or `$request->getQueryParams()`)
- `$totalItems` - Total number of items to paginate
- `$limitOptions` - Optional array of allowed limit values. Default is `[10, 25, 50, 100]`

Basic usage:

```
use Solo\Paginator\Paginator;

class ProductsController
{
    public function list(ServerRequestInterface $request): ResponseInterface
    {
        $queryParams = $request->getQueryParams(); // or $_GET
        $result = Paginator::paginate(
            queryParams: $queryParams,
            totalItems: $totalItems
        );

        return $this->view->render('products/list', [
            'pagination' => $result
        ]);
    }
}
```

Custom limit options:

```
$result = Paginator::paginate(
    queryParams: $queryParams,
    totalItems: 100,
    limitOptions: [20, 40, 60, 80]
);
```

PaginationResult
----------------

[](#paginationresult)

The `paginate()` method returns a `PaginationResult` object with the following properties:

- `page`: Current page number
- `limit`: Items per page limit
- `totalPages`: Total number of pages
- `totalItems`: Total number of items
- `links`: Array of pagination links with url, page number and current state
- `nextPageUrl`: URL for the next page
- `previousPageUrl`: URL for the previous page
- `hasNextPage`: Whether there is a next page
- `hasPreviousPage`: Whether there is a previous page
- `limitOptions`: Array of available limit options with urls

### Template Usage

[](#template-usage)

Basic pagination links:

```

        ...

        >

```

Items per page selector:

```

        >
             items

```

Navigation links:

```
