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

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

wisonlau/pagination
===================

PHP pagination

06PHP

Since Dec 18Pushed 8y agoCompare

[ Source](https://github.com/wisonlau/php-pagination)[ Packagist](https://packagist.org/packages/wisonlau/pagination)[ RSS](/packages/wisonlau-pagination/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

PHP Pagination
==============

[](#php-pagination)

PHP Pagination.

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

[](#screenshots)

These examples show how the pagination 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 "wisonlau/php-pagination"

```

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/jasongrimes/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:

```
