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

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

salernolabs/pagination
======================

A simple class that just wraps some pagination stuff and builds bootstrap HTML

v1.1.0(6y ago)0976MITPHP

Since Aug 3Pushed 6y ago1 watchersCompare

[ Source](https://github.com/salernolabs/pagination)[ Packagist](https://packagist.org/packages/salernolabs/pagination)[ Docs](https://www.salernolabs.com/)[ RSS](/packages/salernolabs-pagination/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (1)Versions (4)Used By (0)

salernolabs/pagination
======================

[](#salernolabspagination)

[![Latest Stable Version](https://camo.githubusercontent.com/023934f9146873b8d0b915d62f7d3334c74c618a102bea99409ceb0b5a6c7f4b/68747470733a2f2f706f7365722e707567782e6f72672f73616c65726e6f6c6162732f706167696e6174696f6e2f762f737461626c65)](https://packagist.org/packages/salernolabs/pagination)[![License](https://camo.githubusercontent.com/3ed2d33f208358b382d3d1657787010a81ddb85ce5a73e66374dcb71f8d2928a/68747470733a2f2f706f7365722e707567782e6f72672f73616c65726e6f6c6162732f706167696e6174696f6e2f6c6963656e7365)](https://packagist.org/packages/salernolabs/pagination)[![Build Status](https://camo.githubusercontent.com/3684f014f1f0496687fff9f1293b63b12c7daa2ad2b7ddcb2f16644a430e9626/68747470733a2f2f7472617669732d63692e636f6d2f73616c65726e6f6c6162732f706167696e6174696f6e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/salernolabs/pagination)

A simple library that wraps some common pagination stuff and can build bootstrap HTML. Yes I know a billion of these exist, I've been offloading old code into individual tested libraries for organization purposes as I move some sites over to Symfony. I may add more formatters at some point, I've been playing with material ui as well, but its not here yet. PR's welcome.

[![Example Pagination Image](docs/images/pagination.png)](docs/images/pagination.png)

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

[](#installation)

```
composer require salernolabs/pagination

```

How to Use
----------

[](#how-to-use)

The idea is to build a pagination object (base or formatted), input some values, retrieve all the pagination info plus html you want.

### Base Pagination Class

[](#base-pagination-class)

The constructor takes several optional arguments. They can also be set with set\* methods.

```
$p = new \SalernoLabs\Pagination\Pagination(
  $pageNumber,
  $numberOfItemsPerPage,
  $totalItems
);

```

Get all the calculated pagination data with `$p->getPaginationData()`;

### PageData Response Class

[](#pagedata-response-class)

The `->getPaginationData()` method will return the [PageData](src/PageData.php) response object. The following methods are available on this object:

MethodReturn TypeInfo`getPageNumber()`intThe current page number, unless it exceeds calculated total pages in which case the last page number is returned.`getTotalItems()`intThe total number of items, this is what you originally entered`getItemsPerPage()`intThe total number of items per page, this is what you originally entered.`getOffset()`intThe calculated database row offset value, suitable for queries`getTotalPages()`intThe calculated total number of pages### BootstrapHTML Generator

[](#bootstraphtml-generator)

The [BootstrapHTML](src/Formatter/BootstrapHTML.php) formatter object extends the base pagination class and provides an extra function for generating HTML suitable for raw output in a template on a site that includes the [Bootstrap](https://getbootstrap.com/) library.

#### `->generateOutput($paginationUrl, $pageNumberConstant, $additionalUrlData)`

[](#-generateoutputpaginationurl-pagenumberconstant-additionalurldata)

This method will generate the output for you using the input parameters to format the urls. If your paginated URLs are of the format `/news/1` for page 1, `/news/2` etc, your first parameter would be `'/news/#'`.

If your URL format is more like `'/articles/index?pageNumber=44'` you could do `'/articles/index?pageNumber=#'`

If you need to change the value `#` in the url template, the second parameter can change it.

Finally the third parameter just adds extra stuff to the end of your URLs.

#### Usage Example

[](#usage-example)

```
$articleCount = /* query article count */ 500;

$pagination = new \SalernoLabs\Pagination\Formatter\BootstrapHTML();
$pagination
    ->setPageNumber(1)
    ->setNumberOfItemsPerPage(20)
    ->setTotalItems($articleCount);
$page = $pagination->getPaginationData();

// eg. LIMIT $page->getOffset(), $page->getItemsPerPage()

$paginationHTML = $pagination->generateOutput('/news/#', '#');

```

At this point you should have the HTML you need to output.

#### Customizing the HTML

[](#customizing-the-html)

There are some extra methods in formatters to tweak the output of the HTML. They are as follows:

MethodDefaultInfo`setNextButton()``&rsaquo;`Sets the text for the "next" button.`setPreviousButton()``&lsaquo;`Sets the text for the "previous" button.`setFirstButton()``&laquo;`Sets the text for the "first" button.`setLastButton()``&raquo;`Sets the text for the "last" button.`setSpace()``&nbsp;`Sets the string to use for spaces.`setItemStride()``5`Sets the stride, basically controls the number of number buttons. A value of five would show five before the current value and five including and after the current value for a total of 10.### Testing

[](#testing)

Testing is just PHPunit. Example build with coverage report if you've loaded composer dev dependencies:

```
php vendor/phpunit/phpunit/phpunit --coverage-html build/coverage-report

```

We aimed for 100% coverage in version 1.#

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity61

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 ~0 days

Total

3

Last Release

2523d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/155974?v=4)[Eric Salerno](/maintainers/ericsalerno)[@ericsalerno](https://github.com/ericsalerno)

---

Top Contributors

[![ericsalerno](https://avatars.githubusercontent.com/u/155974?v=4)](https://github.com/ericsalerno "ericsalerno (8 commits)")

---

Tags

bootstraphelperpaginationphp

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

PHPackages © 2026

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