Lampager-cakephp: Rapid Pagination for CakePHP

Lampager for CakePHP

Rapid pagination without using OFFSET

Requirements

Note

Installing

composer require lampager/lampager-cakephp:^2.0

For SQLite users, see SQLite to configure.

Basic Usage

Simply install as a Composer package and use in one or more of the following methods:

  • Use in Controller (via \Lampager\Cake\Datasource\Paginator)
  • Use in Table (via \Lampager\Cake\Model\Behavior\LampagerBehavior)

Use in Controller

At first, load the default Paginator component with the \Lampager\Cake\Datasource\Paginator in your Controller class (AppController is preferable).

namespace App\Controller;

use Cake\Controller\Controller;
use Lampager\Cake\Datasource\Paginator;

class AppController extends Controller
{
    public function initialize(): void
    {
        parent::initialize();

        $this->loadComponent('Paginator', [
            'paginator' => new Paginator(),
        ]);
    }
}

Use in a way described in the Cookbook: Pagination. Note the options that are specific to Lampager such as forward, seekable, or cursor.

$query = $this->Posts
    ->where(['Posts.type' => 'public'])
    ->orderDesc('created')
    ->orderDesc('id')
    ->limit(10);

$posts = $this->paginate($query, [
    'forward' => true,
    'seekable' => true,
    'cursor' => [
        'id' => 4,
        'created' => '2020-01-01 10:00:00',
    ],
]);

$this->set('posts', $posts);

Use in Table

Initialize LampagerBehavior in your Table class (AppTable is preferable) and simply use lampager() there.

namespace App\Model\Table;

use Cake\ORM\Table;
use Lampager\Cake\Model\Behavior\LampagerBehavior;

class AppTable extends Table
{
    public function initialize(array $config): void
    {
        parent::initialize($config);

        $this->addBehavior(LampagerBehavior::class);
    }
}

The query builder (\Lampager\Cake\ORM\Query) extends the plain old \Cake\ORM\Query and is mixed in with \Lampager\Paginator. Note that some of the methods in \Lampager\Paginator, viz., orderBy(), orderByDesc(), and clearOrderBy() are not exposed because their method signatures are not compatible with the CakePHP query builder.

$cursor = [
    'id' => 4,
    'created' => '2020-01-01 10:00:00',
    'modified' => '2020-01-01 12:00:00',
];

/** @var \Lampager\Cake\PaginationResult $latest */
$latest = $this->lampager()
    ->forward()
    ->seekable()
    ->cursor($cursor)
    ->limit(10)
    ->orderDesc('Posts.modified')
    ->orderDesc('Posts.created')
    ->orderDesc('Posts.id');

foreach ($latest as $post) {
    /** @var \Cake\ORM\Entity $post */
    debug($post->id);
    debug($post->created);
    debug($post->modified);
}

The methods from the CakePHP query builder, e.g., where(), are available. \Cake\Database\Expression\QueryExpression is accepted as well.

/** @var \Lampager\Cake\PaginationResult $drafts */
$drafts = $this->lampager()
    ->where(['type' => 'draft'])
    ->forward()
    ->seekable()
    ->cursor($cursor)
    ->limit(10)
    ->orderDesc($this->query()->newExpr('modified'))
    ->orderDesc($this->query()->newExpr('created'))
    ->orderDesc($this->query()->newExpr('id'));

/** @var \Cake\ORM\Entity $sample */
$sample = $drafts->sample();

/** @var int $count */
$count = $drafts->count();

Classes

See also: lampager/lampager.

NameTypeParent Class
Implemented Interface
Description
Lampager\Cake\ORM\QueryClassCake\ORM\QueryFluent factory implementation for CakePHP
Lampager\Cake\Model\Behavior\LampagerBehaviorClassCake\ORM\BehaviorCakePHP behavior which returns Lampager\Cake\ORM\Query
Lampager\Cake\Datasource\PaginatorClassCake\Datasource\PaginatorCakePHP paginatior which delegates to Lampager\Cake\ORM\Query
Lampager\Cake\PaginatorClassLampager\PaginatorPaginator implementation for CakePHP
Lampager\Cake\ArrayProcessorClassLampager\ArrayProcessorProcessor implementation for CakePHP
Lampager\Cake\PaginationResultClassCake\Datasource\ResultSetInterfacePaginationResult implementation for CakePHP
Lampager\Cake\Database\SqliteCompilerClassCake\Database\SqliteCompilerQuery compiler implementation for SQLite
Lampager\Cake\Database\Driver\SqliteClassCake\Database\Driver\SqliteDriver implementation which delegates to Lampager\Cake\Database\SqliteCompiler

Note that \Lampager\Cake\PaginationResult does not extend \Lampager\PaginationResult as it conflicts with \Cake\Datasource\ResultSetInterface.

API

See also: lampager/lampager.

LampagerBehavior::lampager()

Build a Lampager query from Table in exactly the same way as CakePHP.

LampagerBehavior::lampager(): \Lampager\Cake\ORM\Query

Paginator::__construct()
Paginator::create()

Create a new paginator instance. These methods are not intended to be directly used in your code.

static Paginator::create(\Cake\ORM\Query $builder): static
Paginator::__construct(\Cake\ORM\Query $builder)

Paginator::transform()

Transform a Lampager query into a CakePHP query.

Paginator::transform(\Lampager\Query $query): \Cake\ORM\Query

Paginator::build()

Perform configure + transform.

Paginator::build(\Lampager\Contracts\Cursor|array $cursor = []): \Cake\ORM\Query

Paginator::paginate()

Perform configure + transform + process.

Paginator::paginate(\Lampager\Contracts\Cursor|array $cursor = []): \Lampager\Cake\PaginationResult

Arguments

  • (mixed) $cursor
    An associative array that contains $column => $value or an object that implements \Lampager\Contracts\Cursor. It must be all-or-nothing.
    • For the initial page, omit this parameter or pass an empty array.
    • For the subsequent pages, pass all the parameters. The partial one is not allowed.

Return Value

e.g.,

(Default format when using \Cake\ORM\Query)

object(Lampager\Cake\PaginationResult)#1 (6) {
  ["(help)"]=>
  string(44) "This is a Lampager Pagination Result object."
  ["records"]=>
  array(3) {
    [0]=>
    object(Cake\ORM\Entity)#2 (11) { ... }
    [1]=>
    object(Cake\ORM\Entity)#3 (11) { ... }
    [2]=>
    object(Cake\ORM\Entity)#4 (11) { ... }
  ["hasPrevious"]=>
  bool(false)
  ["previousCursor"]=>
  NULL
  ["hasNext"]=>
  bool(true)
  ["nextCursor"]=>
  array(2) {
    ["created"]=>
    object(Cake\I18n\Time)#5 (3) {
      ["date"]=>
      string(26) "2017-01-01 10:00:00.000000"
      ["timezone_type"]=>
      int(3)
      ["timezone"]=>
      string(3) "UTC"
    }
    ["id"]=>
    int(1)
  }
}

PaginationResult::__call()

\Lampager\Cake\PaginationResult implements \Cake\Datasource\ResultSetInterface. For how to make the best use of the PaginationResult, please refer to the Cookbook: Working with Result Sets.

Examples

This section describes the practical usage of lampager-cakephp.

Use in Controller

The example below shows how to accept a cursor parameter from a request and pass it through PaginatorComponent::paginate(). Be sure that your AppController has properly initialized Paginator as above.

namespace App\Controller;

class PostsController extends AppController
{
    /**
     * This method shows how to pass options by a query and array.
     */
    public function query(): void
    {
        // Get cursor parameters
        $previous = json_decode($this->request->getQuery('previous_cursor'), true);
        $next = json_decode($this->request->getQuery('next_cursor'), true);
        $cursor = $previous ?: $next ?: [];

        // Query expression can be passed to PaginatorComponent::paginate() as normal
        $query = $this->Posts
            ->where(['Posts.type' => 'public'])
            ->orderDesc('created')
            ->orderDesc('id')
            ->limit(15);

        /** @var \Lampager\Cake\PaginationResult<\Cake\ORM\Entity> $posts */
        $posts = $this->paginate($query, [
            // If the previous_cursor is not set, paginate forward; otherwise backward
            'forward' => !$previous,
            'cursor' => $cursor,
            'seekable' => true,
        ]);

        $this->set('posts', $posts);
    }

    /**
     * This method shows how to pass options from an array.
     */
    public function options(): void
    {
        // Get cursor parameters
        $previous = json_decode($this->request->getQuery('previous_cursor'), true);
        $next = json_decode($this->request->getQuery('next_cursor'), true);
        $cursor = $previous ?: $next ?: [];

        /** @var \Lampager\Cake\PaginationResult<\Cake\ORM\Entity> $posts */
        $posts = $this->paginate('Posts', [
            // Lampager options
            // If the previous_cursor is not set, paginate forward; otherwise backward
            'forward' => !$previous,
            'cursor' => $cursor,
            'seekable' => true,

            // PaginatorComponent config
            'conditions' => [
                'type' => 'public',
            ],
            'order' => [
                'created' => 'DESC',
                'id' => 'DESC',
            ],
            'limit' => 15,
        ]);

        $this->set('posts', $posts);
    }
}

And the pagination links can be output as follows:

// If there is a next page, print pagination link
if ($posts->hasPrevious) {
    echo $this->Html->link('<< Previous', [
        'controller' => 'posts',
        'action' => 'index',
        '?' => [
            'previous_cursor' => json_encode($posts->previousCursor),
        ],
    ]);
}

// If there is a next page, print pagination link
if ($posts->hasNext) {
    echo $this->Html->link('Next >>', [
        'controller' => 'posts',
        'action' => 'index',
        '?' => [
            'next_cursor' => json_encode($posts->nextCursor),
        ],
    ]);
}

Supported database engines

MySQL, MariaDB, and PostgreSQL

Supported!

Microsoft SQL Server

Not supported.

SQLite

Supported but requires an additional configuration.

In SQLite UNION ALL statements cannot combine SELECT statements that have ORDER BY clause. In order to get this to work, those SELECT statements have to be wrapped by a subquery like SELECT * FROM (...). CakePHP not natively handling this situation, Lampager for CakePHP introduces \Lampager\Cake\Database\Driver\Sqlite that needs to be installed on your application. Configure like the following in your config/app.php:

return [
    'Datasources' => [
        'default' => [
            'className' => Connection::class,
            'driver' => \Lampager\Cake\Database\Driver\Sqlite::class,
            'username' => '********',
            'password' => '********',
            'database' => '********',
        ],
    ],
];

Author: lampager
Source Code: https://github.com/lampager/lampager-cakephp 
License: MIT license

#php #cakephp #pagination 

What is GEEK

Buddha Community

Lampager-cakephp: Rapid Pagination for CakePHP

Lampager-cakephp: Rapid Pagination for CakePHP

Lampager for CakePHP

Rapid pagination without using OFFSET

Requirements

Note

Installing

composer require lampager/lampager-cakephp:^2.0

For SQLite users, see SQLite to configure.

Basic Usage

Simply install as a Composer package and use in one or more of the following methods:

  • Use in Controller (via \Lampager\Cake\Datasource\Paginator)
  • Use in Table (via \Lampager\Cake\Model\Behavior\LampagerBehavior)

Use in Controller

At first, load the default Paginator component with the \Lampager\Cake\Datasource\Paginator in your Controller class (AppController is preferable).

namespace App\Controller;

use Cake\Controller\Controller;
use Lampager\Cake\Datasource\Paginator;

class AppController extends Controller
{
    public function initialize(): void
    {
        parent::initialize();

        $this->loadComponent('Paginator', [
            'paginator' => new Paginator(),
        ]);
    }
}

Use in a way described in the Cookbook: Pagination. Note the options that are specific to Lampager such as forward, seekable, or cursor.

$query = $this->Posts
    ->where(['Posts.type' => 'public'])
    ->orderDesc('created')
    ->orderDesc('id')
    ->limit(10);

$posts = $this->paginate($query, [
    'forward' => true,
    'seekable' => true,
    'cursor' => [
        'id' => 4,
        'created' => '2020-01-01 10:00:00',
    ],
]);

$this->set('posts', $posts);

Use in Table

Initialize LampagerBehavior in your Table class (AppTable is preferable) and simply use lampager() there.

namespace App\Model\Table;

use Cake\ORM\Table;
use Lampager\Cake\Model\Behavior\LampagerBehavior;

class AppTable extends Table
{
    public function initialize(array $config): void
    {
        parent::initialize($config);

        $this->addBehavior(LampagerBehavior::class);
    }
}

The query builder (\Lampager\Cake\ORM\Query) extends the plain old \Cake\ORM\Query and is mixed in with \Lampager\Paginator. Note that some of the methods in \Lampager\Paginator, viz., orderBy(), orderByDesc(), and clearOrderBy() are not exposed because their method signatures are not compatible with the CakePHP query builder.

$cursor = [
    'id' => 4,
    'created' => '2020-01-01 10:00:00',
    'modified' => '2020-01-01 12:00:00',
];

/** @var \Lampager\Cake\PaginationResult $latest */
$latest = $this->lampager()
    ->forward()
    ->seekable()
    ->cursor($cursor)
    ->limit(10)
    ->orderDesc('Posts.modified')
    ->orderDesc('Posts.created')
    ->orderDesc('Posts.id');

foreach ($latest as $post) {
    /** @var \Cake\ORM\Entity $post */
    debug($post->id);
    debug($post->created);
    debug($post->modified);
}

The methods from the CakePHP query builder, e.g., where(), are available. \Cake\Database\Expression\QueryExpression is accepted as well.

/** @var \Lampager\Cake\PaginationResult $drafts */
$drafts = $this->lampager()
    ->where(['type' => 'draft'])
    ->forward()
    ->seekable()
    ->cursor($cursor)
    ->limit(10)
    ->orderDesc($this->query()->newExpr('modified'))
    ->orderDesc($this->query()->newExpr('created'))
    ->orderDesc($this->query()->newExpr('id'));

/** @var \Cake\ORM\Entity $sample */
$sample = $drafts->sample();

/** @var int $count */
$count = $drafts->count();

Classes

See also: lampager/lampager.

NameTypeParent Class
Implemented Interface
Description
Lampager\Cake\ORM\QueryClassCake\ORM\QueryFluent factory implementation for CakePHP
Lampager\Cake\Model\Behavior\LampagerBehaviorClassCake\ORM\BehaviorCakePHP behavior which returns Lampager\Cake\ORM\Query
Lampager\Cake\Datasource\PaginatorClassCake\Datasource\PaginatorCakePHP paginatior which delegates to Lampager\Cake\ORM\Query
Lampager\Cake\PaginatorClassLampager\PaginatorPaginator implementation for CakePHP
Lampager\Cake\ArrayProcessorClassLampager\ArrayProcessorProcessor implementation for CakePHP
Lampager\Cake\PaginationResultClassCake\Datasource\ResultSetInterfacePaginationResult implementation for CakePHP
Lampager\Cake\Database\SqliteCompilerClassCake\Database\SqliteCompilerQuery compiler implementation for SQLite
Lampager\Cake\Database\Driver\SqliteClassCake\Database\Driver\SqliteDriver implementation which delegates to Lampager\Cake\Database\SqliteCompiler

Note that \Lampager\Cake\PaginationResult does not extend \Lampager\PaginationResult as it conflicts with \Cake\Datasource\ResultSetInterface.

API

See also: lampager/lampager.

LampagerBehavior::lampager()

Build a Lampager query from Table in exactly the same way as CakePHP.

LampagerBehavior::lampager(): \Lampager\Cake\ORM\Query

Paginator::__construct()
Paginator::create()

Create a new paginator instance. These methods are not intended to be directly used in your code.

static Paginator::create(\Cake\ORM\Query $builder): static
Paginator::__construct(\Cake\ORM\Query $builder)

Paginator::transform()

Transform a Lampager query into a CakePHP query.

Paginator::transform(\Lampager\Query $query): \Cake\ORM\Query

Paginator::build()

Perform configure + transform.

Paginator::build(\Lampager\Contracts\Cursor|array $cursor = []): \Cake\ORM\Query

Paginator::paginate()

Perform configure + transform + process.

Paginator::paginate(\Lampager\Contracts\Cursor|array $cursor = []): \Lampager\Cake\PaginationResult

Arguments

  • (mixed) $cursor
    An associative array that contains $column => $value or an object that implements \Lampager\Contracts\Cursor. It must be all-or-nothing.
    • For the initial page, omit this parameter or pass an empty array.
    • For the subsequent pages, pass all the parameters. The partial one is not allowed.

Return Value

e.g.,

(Default format when using \Cake\ORM\Query)

object(Lampager\Cake\PaginationResult)#1 (6) {
  ["(help)"]=>
  string(44) "This is a Lampager Pagination Result object."
  ["records"]=>
  array(3) {
    [0]=>
    object(Cake\ORM\Entity)#2 (11) { ... }
    [1]=>
    object(Cake\ORM\Entity)#3 (11) { ... }
    [2]=>
    object(Cake\ORM\Entity)#4 (11) { ... }
  ["hasPrevious"]=>
  bool(false)
  ["previousCursor"]=>
  NULL
  ["hasNext"]=>
  bool(true)
  ["nextCursor"]=>
  array(2) {
    ["created"]=>
    object(Cake\I18n\Time)#5 (3) {
      ["date"]=>
      string(26) "2017-01-01 10:00:00.000000"
      ["timezone_type"]=>
      int(3)
      ["timezone"]=>
      string(3) "UTC"
    }
    ["id"]=>
    int(1)
  }
}

PaginationResult::__call()

\Lampager\Cake\PaginationResult implements \Cake\Datasource\ResultSetInterface. For how to make the best use of the PaginationResult, please refer to the Cookbook: Working with Result Sets.

Examples

This section describes the practical usage of lampager-cakephp.

Use in Controller

The example below shows how to accept a cursor parameter from a request and pass it through PaginatorComponent::paginate(). Be sure that your AppController has properly initialized Paginator as above.

namespace App\Controller;

class PostsController extends AppController
{
    /**
     * This method shows how to pass options by a query and array.
     */
    public function query(): void
    {
        // Get cursor parameters
        $previous = json_decode($this->request->getQuery('previous_cursor'), true);
        $next = json_decode($this->request->getQuery('next_cursor'), true);
        $cursor = $previous ?: $next ?: [];

        // Query expression can be passed to PaginatorComponent::paginate() as normal
        $query = $this->Posts
            ->where(['Posts.type' => 'public'])
            ->orderDesc('created')
            ->orderDesc('id')
            ->limit(15);

        /** @var \Lampager\Cake\PaginationResult<\Cake\ORM\Entity> $posts */
        $posts = $this->paginate($query, [
            // If the previous_cursor is not set, paginate forward; otherwise backward
            'forward' => !$previous,
            'cursor' => $cursor,
            'seekable' => true,
        ]);

        $this->set('posts', $posts);
    }

    /**
     * This method shows how to pass options from an array.
     */
    public function options(): void
    {
        // Get cursor parameters
        $previous = json_decode($this->request->getQuery('previous_cursor'), true);
        $next = json_decode($this->request->getQuery('next_cursor'), true);
        $cursor = $previous ?: $next ?: [];

        /** @var \Lampager\Cake\PaginationResult<\Cake\ORM\Entity> $posts */
        $posts = $this->paginate('Posts', [
            // Lampager options
            // If the previous_cursor is not set, paginate forward; otherwise backward
            'forward' => !$previous,
            'cursor' => $cursor,
            'seekable' => true,

            // PaginatorComponent config
            'conditions' => [
                'type' => 'public',
            ],
            'order' => [
                'created' => 'DESC',
                'id' => 'DESC',
            ],
            'limit' => 15,
        ]);

        $this->set('posts', $posts);
    }
}

And the pagination links can be output as follows:

// If there is a next page, print pagination link
if ($posts->hasPrevious) {
    echo $this->Html->link('<< Previous', [
        'controller' => 'posts',
        'action' => 'index',
        '?' => [
            'previous_cursor' => json_encode($posts->previousCursor),
        ],
    ]);
}

// If there is a next page, print pagination link
if ($posts->hasNext) {
    echo $this->Html->link('Next >>', [
        'controller' => 'posts',
        'action' => 'index',
        '?' => [
            'next_cursor' => json_encode($posts->nextCursor),
        ],
    ]);
}

Supported database engines

MySQL, MariaDB, and PostgreSQL

Supported!

Microsoft SQL Server

Not supported.

SQLite

Supported but requires an additional configuration.

In SQLite UNION ALL statements cannot combine SELECT statements that have ORDER BY clause. In order to get this to work, those SELECT statements have to be wrapped by a subquery like SELECT * FROM (...). CakePHP not natively handling this situation, Lampager for CakePHP introduces \Lampager\Cake\Database\Driver\Sqlite that needs to be installed on your application. Configure like the following in your config/app.php:

return [
    'Datasources' => [
        'default' => [
            'className' => Connection::class,
            'driver' => \Lampager\Cake\Database\Driver\Sqlite::class,
            'username' => '********',
            'password' => '********',
            'database' => '********',
        ],
    ],
];

Author: lampager
Source Code: https://github.com/lampager/lampager-cakephp 
License: MIT license

#php #cakephp #pagination 

Hire Dedicated CakePHP Developers | Hire CakePHP Developers USA

The foundational structure behind removing the monotony from the development process is obtained by the CakePHP framework. The framework is open-sourced and helps in creating web applications rapidly.

Want a web application in a short time duration with the CakePHP framework?

Hire Dedicated CakePHP developers from the experts WebClues Infotech and take the step toward business growth. The developer WebClues Infotech offers to its clients is highly skilled and expert in the project requirements mentioned by the customers.

Look no further and share with us your requirements to see our commitments in action

Share your requirements here https://www.webcluesinfotech.com/contact-us/

Book Free Interview with CakePHP Developers: https://bit.ly/3dDShFg

#hire dedicated cakephp developers #hire cakephp developer #hire dedicated cakephp web developers #hire dedicated cakephp developers or programmer #hire cakephp developer #hire cakephp developer india

Pagination Example In Laravel

In this post I will show you pagination example in laravel, as we all know pagination is very common feature in all websites, if we want to display specific number of details or images then we can use pagination.

aravel provide paginate method and it will automatically takes care of setting the proper limit and offset based on the current page being viewed by the user.here i will show you how to use pagination in laravel, So I have try paginate method in laravel.

Pagination Example In Laravel

https://websolutionstuff.com/post/pagination-example-in-laravel

#pagination example in laravel #laravel #pagination #paginate method #how to use pagination in laravel #pagination in laravel

CakePHP Development Company | Hire CakePHP Developers | Skenix

Skenix Infotech is the best CakePHP development company in India. We are committed to providing personalized solutions as per the needs and requirements of the clients. We keep updated about the current improved technologies, using upgraded technologies. We provide group CakePHP Web Services at the most affordable prices. If you are searching to Hire CakePHP Developers for your website building, Contact us immediately.

Visit us for more details about Company and our Services:

Our Website: www.skenix.com
Mail: info@skenix.com
Phone: +91-8160248529
Address: 108 - 1st floor, Vraj Complex, Parivar Chowkdi, Waghodia Rd, Kendranagar, Vadodara, Gujarat 390025

#Cakephp Development Company #Hire Cakephp Developers #Cakephp Development Services #Cakephp Web Services #Cakephp Development

Cakephp-api-pagination: CakePHP API Pagination

CakePHP API Pagination

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

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

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:

$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

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

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING and CONDUCT for details.

Security

If you discover any security related issues, please email bryan@bryan-crowe.com instead of using the issue tracker.

Credits

Author: Bcrowe
Source Code: https://github.com/bcrowe/cakephp-api-pagination 
License: MIT license

#php #cakephp #api #pagination