PHPackages                             tbrouard/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. tbrouard/paginator

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

tbrouard/paginator
==================

A lightweight PHP paginator, for generating pagination controls in the style of Stack Overflow and Flickr. The 'first' and 'last' page links are shown inline as page numbers, and excess page numbers are replaced by ellipses.

1.0.10(5mo ago)020MITPHPPHP &gt;=5.3.0

Since Nov 13Pushed 1mo agoCompare

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

READMEChangelog (1)Dependencies (1)Versions (6)Used By (0)

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

[](#php-paginator)

A lightweight PHP paginator, for generating pagination controls in the style of Stack Overflow and Flickr. The "first" and "last" page links are shown inline as page numbers, and excess page numbers are replaced by ellipses.

Screenshots
-----------

[](#screenshots)

These examples show how the paginator handles overflow when there are a lot of pages. They're rendered using the sample templates provided in the [examples](examples/) directory, which depend on Twitter Bootstrap. You can easily use your own custom HTML to render the pagination control instead.

Default template:

[![](examples/screenshot-default-first.png)](examples/screenshot-default-first.png)
[![](examples/screenshot-default-mid.png)](examples/screenshot-default-mid.png)
[![](examples/screenshot-default-last.png)](examples/screenshot-default-last.png)

Small template (useful for mobile interfaces):

[![](examples/screenshot-small-first.png)](examples/screenshot-small-first.png)
[![](examples/screenshot-small-mid.png)](examples/screenshot-small-mid.png)
[![](examples/screenshot-small-last.png)](examples/screenshot-small-last.png)

The small template renders the page number as a select list to save space:

[![](examples/screenshot-small-mid-open.png)](examples/screenshot-small-mid-open.png)

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

[](#installation)

Install with composer:

```
composer require "tbrouard/paginator:~1.0"

```

Basic usage
-----------

[](#basic-usage)

Here's a quick example using the defaults:

```

```

This will output the following:

[![](examples/screenshot-default-mid.png)](examples/screenshot-default-mid.png)

```

  &laquo; Previous
  1
  ...
  5
  6
  7
  8
  9
  10
  11
  12
  ...
  20
  Next &raquo;

```

To render it with one of the other example templates, just make sure the variable is named `$paginator` and then include the template file:

```
$paginator = new Paginator($totalItems, $itemsPerPage, $currentPage, $urlPattern);

include '../vendor/tbrouard/paginator/examples/pagerSmall.phtml';

```

[![](examples/screenshot-small-mid.png)](examples/screenshot-small-mid.png)

If the example templates don't suit you, you can iterate over the paginated data to render your own pagination control.

Rendering a custom pagination control
-------------------------------------

[](#rendering-a-custom-pagination-control)

Use `$paginator->getPages()`, `$paginator->getNextUrl()`, and `$paginator->getPrevUrl()` to render a pagination control with your own HTML. For example:

```
