Download the PHP package bcrowe/cakephp-api-pagination without Composer
On this page you can find all versions of the php package bcrowe/cakephp-api-pagination. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download bcrowe/cakephp-api-pagination
More information about bcrowe/cakephp-api-pagination
Files in bcrowe/cakephp-api-pagination
Package cakephp-api-pagination
Short Description CakePHP 4 plugin that injects pagination information into API responses.
License MIT
Homepage https://github.com/bcrowe/cakephp-api-pagination
Informations about the package cakephp-api-pagination
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
Via Composer
Load the plugin by adding $this->addPlugin('BryanCrowe/ApiPagination');
to the bootsrap
method in your project’s src/Application.php
:
Usage
Make sure your application has been set up to use data views; see the Enabling Data Views in Your Application section of the CakePHP documentation.
Then, load ApiPaginationComponent
:
Then, go ahead and set your paginated view variable like so:
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:
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
forArticlesController
.
An example using all these configuration keys:
This configuration would yield:
Changelog
Please see CHANGELOG for more information what has changed recently.
Testing
Contributing
Please see CONDUCT for details.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
- Bryan Crowe
- All Contributors
License
The MIT License (MIT). Please see License File for more information.