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

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

soup/paginator
==============

Paginator is a simple class that allows you to create pagination. It doesn't require any database connection. It is compatible with Twitter's Bootstrap Framework, by using the CSS class pagination that is also attached.

2.1.1(10y ago)351.5k6[3 issues](https://github.com/mardix/Paginator/issues)MITPHPPHP &gt;=5.4.0

Since Jan 11Pushed 10y ago4 watchersCompare

[ Source](https://github.com/mardix/Paginator)[ Packagist](https://packagist.org/packages/soup/paginator)[ Docs](https://github.com/mardix/Paginator)[ RSS](/packages/soup-paginator/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (9)Used By (0)

Paginator 2.x.x
===============

[](#paginator-2xx)

#### A paginator that makes it easy and simple

[](#a-paginator-that-makes-it-easy-and-simple)

---

Name: [Paginator](http://github.com/mardix/Paginator)

License: MIT

Author: [Mardix](http://github.com/mardix)

Version : 2.x.x

Requirements: PHP &gt;= 5.4

---

About Paginator
---------------

[](#about-paginator)

Paginator is a simple class that allows you to create pagination for your application. It doesn't require any database connection. It only requires the total of items found and from there it will create a pagination that can be export to HTML or Array. It is also compatible with Twitter's Bootstrap Framework.

---

Install Paginator
-----------------

[](#install-paginator)

You can just download Paginator as is, or with Composer.

To install with composer, add the following in the require key in your **composer.json** file

```
"voodoophp/paginator": "2.*"

```

composer.json

```
{
    "name": "voodoophp/myapp",
    "description": "My awesome Voodoo App",
    "require": {
        "voodoophp/paginator": "2.*"
    }
}

```

---

### Create a Pagination

[](#create-a-pagination)

Paginator makes it easy to create pagination. It only requires the URL that contains the page number pattern, the total items, and the total of items per page.

```
http://site.com/search?q=flower&page=15

```

or

```
http://site.com/genres/pop/page/15

```

Paginator will automatically match the page number with the url above, and create pagination for the rest of the pages based on the total items and items per page provided.

### Catching the page number

[](#catching-the-page-number)

Paginator requires the keyword **(:num)** in the page number pattern to match the page number in the URL.

Page number pattern are set in the following format

For friendly URL, it will capture

```
/page/(:num)

```

For normal URL, it will capture

```
page=(:num)

```

Page number pattern is set in

```
Voodoo\Paginator::setUrl($url, $pagePattern);

```

On both examples it will catch the page number \[**25**\] and create from there the start and the end of the pagination.

Any variation of the page number pattern is OK, as long as it includes **(:num)**

### A Simple Example

[](#a-simple-example)

```

        Paginator Example

```

Will render something like this:

```
[First] [>] [Last]

```

With links that look like:

```
6

```

---

### Methods

[](#methods)

---

\####Voodoo\\Paginator::\_\_construct() &lt;?php

```
include "src/Voodoo/Paginator.php";

$paginator = new Voodoo\Paginator;

```

---

\####Voodoo\\Paginator::setUrl() To set the url and the page number pattern

```

```

---

\####String Voodoo\\Paginator::toHtml()

Will return a formatted HTML, compatible with Bootstrap framework

```
