Skip to content

MixerAPI CollectionView

Latest Version on Packagist License: MIT Build Coverage Status MixerApi CakePHP Minimum PHP Version

This is an alpha stage plugin.

A simple Collection View for displaying configurable pagination meta data in JSON or XML collection responses. Read more at


You can skip this step if MixerAPI is installed.

composer require mixerapi/collection-view
bin/cake plugin load MixerApi/CollectionView

Alternatively after composer installing you can manually load the plugin in your Application:

# src/Application.php
public function bootstrap(): void
    // other logic...


Your controllers must be using the RequestHandler component. This is typically loaded in your AppController.

# src/Controller/AppController.php
public function initialize(): void
    // other logic... 


That's it, you're done. Perform application/xml or application/json requests as normal. You may also request by .xml or .json extensions (assuming you've enabled them in your config/routes.php). This plugin will only modify collections (e.g. controller::index action) requests, not item (e.g. controller::view action) requests.

JSON sample

    "collection": {
        "url": "/films?page=3&direction=desc",
        "count": 20,
        "total": 1000,
        "pages": 50,
        "next": "/films?page=4",
        "prev": "/films?page=2",
        "first": "/films",
        "last": "/films?page=50"
    "data": [
            "id": 1,
            "first_name": "PENELOPE",
            "last_name": "GUINESS",
            "modified": "2006-02-15T04:34:33+00:00",
            "films": [
                    "id": 1,
                    "title": "ACADEMY DINOSAUR",
                    "description": "A Epic Drama of a Feminist And a Mad Scientist who must Battle a Teacher in The Canadian Rockies",
                    "release_year": "2006",
                    "language_id": 1,
                    "rental_duration": 6,
                    "length": 86,
                    "rating": "PG",
                    "special_features": "Deleted Scenes,Behind the Scenes",
                    "modified": "2006-02-15T05:03:42+00:00"

XML sample

    <modified>2/15/06, 4:34 AM</modified>
      <title>ACADEMY DINOSAUR</title>
      <description>A Epic Drama of a Feminist And a Mad Scientist who must Battle a Teacher in The Canadian Rockies</description>
      <special_features>Deleted Scenes,Behind the Scenes</special_features>
      <modified>2/15/06, 5:03 AM</modified>


This is optional. You can alter the names of the response keys, simply create a config/collection_view.php file. Using the example below we can change the collection key to pagination, data to items, and alter some key names within our new pagination object. Just keep the mapped items {{names}} as-is.

# config/collection_view.php
return [
    'CollectionView' => [
        'pagination' => '{{collection}}', // array that holds pagination data
        'pagination.url' => '{{url}}', // url of current page
        'pagination.pageCount' => '{{count}}', // items on the page
        'pagination.totalCount' => '{{total}}', // total database records
        'pagination.pages' => '{{pages}}', // total pages
        '' => '{{next}}', // next page url
        'pagination.prev' => '{{prev}}', // previous page url
        'pagination.first' => '{{first}}', // first page url
        'pagination.last' => '{{last}}', // last page url
        'items' => '{{data}}', // the collection of data

Unit Tests


Code Standards

composer check