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

ActiveLibrary

ikkez/f3-pagination
===================

Provides a pagebrowser and some pagination utilities for the PHP Fat-Free Framework

v1.4.5(4y ago)1624.4k—9.1%52GPL-3.0PHP

Since Aug 11Pushed 4y ago3 watchersCompare

[ Source](https://github.com/ikkez/f3-pagination)[ Packagist](https://packagist.org/packages/ikkez/f3-pagination)[ Docs](https://github.com/ikkez/f3-pagination)[ RSS](/packages/ikkez-f3-pagination/feed)WikiDiscussions master Synced 1mo ago

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

F3 Pagination
=============

[](#f3-pagination)

This plugin provides a pagebrowser and some pagination utilities for the PHP Fat-Free Framework.

Requires [PHP Fat-Free Framework](https://github.com/bcosca/fatfree) 3.6.

---

Preview
-------

[](#preview)

The default pagebrowser template contains the default [bootstrap](http://getbootstrap.com/components/#pagination) class, which can look like this:

[![pagebrowser](https://camo.githubusercontent.com/8b69ac0463ee875206d6c628b3614a8887d8f51e71c83c220bb1e20cb345afcd/68747470733a2f2f696b6b657a2e64652f6c696e6b65642f7061676562726f777365722e6a7067)](https://camo.githubusercontent.com/8b69ac0463ee875206d6c628b3614a8887d8f51e71c83c220bb1e20cb345afcd/68747470733a2f2f696b6b657a2e64652f6c696e6b65642f7061676562726f777365722e6a7067)

Usage
-----

[](#usage)

### 1. Install

[](#1-install)

Copy pagination.php into your `lib/` folder OR put the file into one of your include paths, you have defined in `AUTOLOAD` (like `$f3->set('AUTOLOAD', 'app/;app/includes');` ).

The Pagination plugin uses a **template file** to generate the pagebrowser. Put this template (`pagebrowser.html`) in your UI folder. (i.e. if you've defined an UI dir like `$f3->set('UI','templates/')`, then move the pagebrowser template in there)

### 2. Routing

[](#2-routing)

To make the routing between pages work, you need to add a new route, containing a token, that could be used by our Pagebrowser.

e.g. if you already use a route like `$f3->route('GET /list', 'Blog->listAllArticles');`you have to add this route too: `$f3->route('GET /list/@page', 'Blog->listAllArticles');`

You can also group them into a single route statement like this:

```
$f3->route(array(
    'GET /list',
    'GET /list/@page'
    ), 'Blog->listAllArticles');
```

### 3. Paginate your Records

[](#3-paginate-your-records)

Within your controller you need to paginate over your records. The most easiest way to do so, is to use a data mapper and its [paginate](http://fatfreeframework.com/cursor#paginate) method.

```
$article = new \DB\SQL\Mapper($f3->get('DB'),'article');

$limit = 10;
$page = \Pagination::findCurrentPage();
$filter = array('active = ?',1);
$option = array('order' => 'datetime DESC');

$subset = $article->paginate($page-1, $limit, $filter, $option);

$f3 = \Base::instance();
$f3->set('articleList', $subset);
```

Now you got the subset of your records in the `articleList` f3 hive key. It's an array that contains information about the pagination state and the subset itself with all records as data mapper objects. Have a look at the [paginate](http://fatfreeframework.com/cursor#paginate) method for detailed description.

But basically, you can loop through the list by using this snippet:

```

  {{ @article.title }}
  {{ @article.text }}

```

### 4. Create the PageBrowser

[](#4-create-the-pagebrowser)

#### Method A: Custom Tag

[](#method-a-custom-tag)

The easiest way to create the pagebrowser now, is to use the custom template tag renderer. This generates the pagebrowser directly from the inside of your template. Therefor just register the pagebrowser right at the start in your `index.php`:

```
\Template::instance()->extend('pagebrowser','\Pagination::renderTag');
```

Now you can use this view helper in your HTML template:

```

```

And you're done! Additional configuration can be done by adding more tag parameters (see below).

#### Method B: render it yourself within your controller

[](#method-b-render-it-yourself-within-your-controller)

```
// [...]
$f3->set('articleList', $subset);
// we continue after the previous example about setting up the record pagination

// build page links
$pages = new Pagination($subset['total'], $subset['limit']);
// add some configuration if needed
$pages->setTemplate('templates/pagebrowser-advanced.html');
// for template usage, serve generated pagebrowser to the hive
$f3->set('pagebrowser', $pages->serve());
```

Now you can use `{{ @pagebrowser | raw }}` in your template, to insert the pagebrowser.

### Configuration

[](#configuration)

Of course you can define another token key in your route, instead of `@page`. Therefor just set it as third argument on instantiation (here without @-symbol).

```
$pages = new Pagination($article_count, $items_per_page, 'paginationToken');
```

If your template is within another sub-directory, or you want to use different templates, you can change the template path with:

```
$pages->setTemplate('templates/pagebrowser.html');
```

The Paginator builds links, depending on the current route. But sometimes you maybe want to serve other pagebrowser link. You can set another link path like this:

```
$pages->setLinkPath('search/results/');
```

It will now build URLs like `search/results/1`, `search/results/2`, `search/results/3`.

You can also prefix your page links for a better visual and SEO experience:

```
$pages->setRouteKeyPrefix('page-');
```

Now your page links will look like these: `list/page-1`, `list/page-2`, `list/page-3`

You can also alter the range of next and previous pages, based on the current page (Default is 2):

```
$pages->setRange(5);
```

---

Of course you can set all of these options in the custom tag too. Just have a look at this fully configured example tag:

```

```

You can also pass template variables to all of those arguments, like `range="{{@range}}"`.

### Testsuite

[](#testsuite)

To add the tests to the fatfree-dev testing bench:

```
// Pagination Tests
$f3->concat('AUTOLOAD',',sugar/Pagination/test/,sugar/Pagination/lib/');
\PaginationTest::init();
```

License
-------

[](#license)

You are allowed to use this plugin under the terms of the GNU General Public License version 3 or later.

Copyright (C) 2022 Christian Knuth \[ikkez\]

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity36

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity65

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

Total

3

Last Release

1553d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/84cac52f5889d2bf6e710f2139dfc884824b2d7ce9c48a3bfe90704a94c85722?d=identicon)[ikkez](/maintainers/ikkez)

---

Top Contributors

[![ikkez](https://avatars.githubusercontent.com/u/1177647?v=4)](https://github.com/ikkez "ikkez (5 commits)")

---

Tags

fat-free-frameworkpaginationpaginationF3fatfreepagebrowser

### Embed Badge

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

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

###  Alternatives

[xfra35/f3-cron

Job scheduling for the PHP Fat-Free Framework

73107.5k](/packages/xfra35-f3-cron)[xfra35/f3-access

Route access control for the PHP Fat-Free Framework

6668.7k1](/packages/xfra35-f3-access)[ikkez/f3-schema-builder

SQL Schema Builder Plugin for PHP Fat-Free Framework

5854.0k4](/packages/ikkez-f3-schema-builder)[xfra35/f3-multilang

Route localization plugin for the PHP Fat-Free Framework

4862.7k1](/packages/xfra35-f3-multilang)[ikkez/f3-cortex

A multi-engine ORM / ODM for the PHP Fat-Free Framework

12040.0k7](/packages/ikkez-f3-cortex)[ikkez/f3-events

Sweet event system for the PHP Fat-Free Framework

2822.1k3](/packages/ikkez-f3-events)

PHPackages © 2026

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