PHPackages                             bcrowe/cakephp-api-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. [API Development](/categories/api)
4. /
5. bcrowe/cakephp-api-pagination

ActiveCakephp-plugin[API Development](/categories/api)

bcrowe/cakephp-api-pagination
=============================

CakePHP 4 plugin that injects pagination information into API responses.

3.0.1(2y ago)3954.1k↑342.9%13[1 PRs](https://github.com/bcrowe/cakephp-api-pagination/pulls)1MITPHPPHP &gt;=7.2CI failing

Since Jul 26Pushed 2y ago4 watchersCompare

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

READMEChangelog (10)Dependencies (4)Versions (21)Used By (1)

CakePHP API Pagination
======================

[](#cakephp-api-pagination)

[![Latest Version on Packagist](https://camo.githubusercontent.com/87733bdcf2afe4ca24fd0e4f569ac2b57824e6bebe9389ce2223e757707a8789/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6263726f77652f63616b657068702d6170692d706167696e6174696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/bcrowe/cakephp-api-pagination)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://github.com/bcrowe/cakephp-api-pagination/workflows/CI/badge.svg)](https://github.com/bcrowe/cakephp-api-pagination/actions)[![Coverage Status](https://camo.githubusercontent.com/922193a68d188564a72d7603e47b118cc66f7a608eaeb28ae84e7239695b8a94/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f6263726f77652f63616b657068702d6170692d706167696e6174696f6e2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/bcrowe/cakephp-api-pagination/code-structure)[![Quality Score](https://camo.githubusercontent.com/a1b6902cfb1661268fd3ec2f5bf0711272d2e3f9a0891d9e3d78e4c8aa874bef/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6263726f77652f63616b657068702d6170692d706167696e6174696f6e2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/bcrowe/cakephp-api-pagination)[![Total Downloads](https://camo.githubusercontent.com/e02ef0bfa6476d82a485acb5640d46db2a6ef7fd84465e9a72e5cf867d35dbd3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6263726f77652f63616b657068702d6170692d706167696e6174696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/bcrowe/cakephp-api-pagination)

This is a simple component for CakePHP 4.2+ which injects pagination information from CakePHP's Paginator into serialized JsonView and XmlView responses.

See `1.x` and `2.x` releases and branches of this plugin for support of previous versions of CakePHP before `4.2`.

Install
-------

[](#install)

Via Composer

```
$ composer require bcrowe/cakephp-api-pagination
```

Load the plugin by adding `$this->addPlugin('BryanCrowe/ApiPagination');` to the `bootsrap` method in your project’s `src/Application.php`:

```
public function bootstrap(): void
{
    parent::bootstrap();

    // ... bootstrap code ...

    // load more plugins here

    $this->addPlugin('BryanCrowe/ApiPagination');
}
```

Usage
-----

[](#usage)

Make sure your application has been set up to use data views; see the [Enabling Data Views in Your Application](https://book.cakephp.org/4/en/views/json-and-xml-views.html#enabling-data-views-in-your-application) section of the CakePHP documentation.

Then, load `ApiPaginationComponent`:

```
$this->loadComponent('BryanCrowe/ApiPagination.ApiPagination');
```

Then, go ahead and set your paginated view variable like so:

```
$this->set('articles', $this->paginate($this->Articles));
$this->viewBuilder()->setOption('serialize', ['articles']);
```

**Note:** It is important that your `serialize` option is an array, e.g. `['articles']`, so that your pagination information can be set under its own pagination key.

Your JsonView and XmlView responses will now contain the pagination information, and will look something like this:

```
{
    "articles": ["...", "...", "..."],
    "pagination": {
        "finder": "all",
        "page": 1,
        "current": 20,
        "count": 5000,
        "perPage": 20,
        "prevPage": false,
        "nextPage": true,
        "pageCount": 250,
        "sort": null,
        "direction": false,
        "limit": null,
        "sortDefault": false,
        "directionDefault": false
    }
}
```

### Configuring the Pagination Output

[](#configuring-the-pagination-output)

ApiPagination has four keys for configuration: `key`, `aliases`, `visible` and `model`.

- `key` allows you to change the name of the pagination key.
- `aliases` allows you to change names of the pagination detail keys.
- `visible` allows you to set which pagination keys will be exposed in the response. **Note:** Whenever setting a key's visibility, make sure to use the aliased name if you've given it one.
- `model` allows you to set the name of the model the pagination is applied on if the controller does not follow CakePHP conventions, e.g. `ArticlesIndexController`. Per default the model is the name of the controller, e.g. `Articles` for `ArticlesController`.

An example using all these configuration keys:

```
$this->loadComponent('BryanCrowe/ApiPagination.ApiPagination', [
    'key' => 'paging',
    'aliases' => [
        'page' => 'currentPage',
        'current' => 'resultCount'
    ],
    'visible' => [
        'currentPage',
        'resultCount',
        'prevPage',
        'nextPage'
    ],
    'model' => 'Articles',
]);
```

This configuration would yield:

```
{
    "articles": ["...", "...", "..."],
    "paging": {
        "prevPage": false,
        "nextPage": true,
        "currentPage": 1,
        "resultCount": 20
    }
}
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Testing
-------

[](#testing)

```
$ composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) and [CONDUCT](CONDUCT.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email instead of using the issue tracker.

Credits
-------

[](#credits)

- [Bryan Crowe](https://github.com/bcrowe)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity40

Moderate usage in the ecosystem

Community24

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 84.1% 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 ~163 days

Recently: every ~256 days

Total

20

Last Release

903d ago

Major Versions

0.0.9 → 1.0.02015-12-07

1.x-dev → 2.0.02020-07-10

2.x-dev → 3.0.02023-07-12

PHP version history (3 changes)0.0.1PHP &gt;=5.4.16

1.2.0PHP &gt;=5.6

2.0.0PHP &gt;=7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/19e009a3db20614ee9d5fa2aa54bec3b7a7bc468e6e567afca15d62ef8fda4b8?d=identicon)[bcrowe](/maintainers/bcrowe)

---

Top Contributors

[![bcrowe](https://avatars.githubusercontent.com/u/752603?v=4)](https://github.com/bcrowe "bcrowe (90 commits)")[![mtak3](https://avatars.githubusercontent.com/u/1726154?v=4)](https://github.com/mtak3 "mtak3 (5 commits)")[![styks1111](https://avatars.githubusercontent.com/u/642930?v=4)](https://github.com/styks1111 "styks1111 (5 commits)")[![ishanvyas22](https://avatars.githubusercontent.com/u/17404636?v=4)](https://github.com/ishanvyas22 "ishanvyas22 (3 commits)")[![LukeC8](https://avatars.githubusercontent.com/u/8444885?v=4)](https://github.com/LukeC8 "LukeC8 (2 commits)")[![pabloelcolombiano](https://avatars.githubusercontent.com/u/23249541?v=4)](https://github.com/pabloelcolombiano "pabloelcolombiano (1 commits)")[![jfalbel](https://avatars.githubusercontent.com/u/38588584?v=4)](https://github.com/jfalbel "jfalbel (1 commits)")

---

Tags

apicakephpcakephp-apicakephp-componentcakephp-json-viewcakephp-plugincakephp-viewcakephp-xml-viewcomponentenvelopemetadatapaginationpaginatorphprest-apiapipaginationcakephpcakephp3cakephp4

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/bcrowe-cakephp-api-pagination/health.svg)

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

###  Alternatives

[dereuromark/cakephp-ide-helper

CakePHP IdeHelper Plugin to improve auto-completion

1882.3M44](/packages/dereuromark-cakephp-ide-helper)[friendsofcake/crud-json-api

Listener for building CakePHP Crud APIs following the JSON API specification.

58458.4k3](/packages/friendsofcake-crud-json-api)[dereuromark/cakephp-tinyauth

A CakePHP plugin to handle user authentication and authorization the easy way.

131240.2k13](/packages/dereuromark-cakephp-tinyauth)[dereuromark/cakephp-setup

A CakePHP plugin containing lots of useful management tools

36199.6k2](/packages/dereuromark-cakephp-setup)[a2design-company/mandrill-cakephp-plugin

Mandrill CakePHP plugin

193.2k](/packages/a2design-company-mandrill-cakephp-plugin)

PHPackages © 2026

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