Download the PHP package josbeir/cakephp-paginator-sortmap without Composer
On this page you can find all versions of the php package josbeir/cakephp-paginator-sortmap. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download josbeir/cakephp-paginator-sortmap
More information about josbeir/cakephp-paginator-sortmap
Files in josbeir/cakephp-paginator-sortmap
Package cakephp-paginator-sortmap
Short Description Paginator with support for custom mappable multi sortable sort keys
License MIT
Informations about the package cakephp-paginator-sortmap
CakePHP Paginator with sortmaps
This plugin is a modified version of the built in cakephp paginator. Instead of using sortWhitelist
there's now a sortMap
option where you can define mappings of fields to sort.
This plugin was created as a proof of concept after some discussion on slack and in an old ticket on the main cake repo.
This plugin also makes pagination work correctly with plugins like Cakephp\Elasticsearch.
Installation
The usual:
composer require josbeir/cakephp-paginator-sortmap
Then enable the plugin by adding it to your Application::bootstrap()
$this->addPlugin('Josbeir/Paginator');
Controller example
Mapping sort => field
In its simplest form you can just use the sortMap to rename sort keys:
Will result in sort order
Mapping multiple fields under one sort
A mapping can also consist of multiple sort fields grouped together:
So when sorting on foo
the following order clause will be generated and passed to the the datasource object (where the direction is passed from the foo
argument to both fields'
`
You could also assign fixed sort conditions to specific fields in your sortmap. These conditions will then be used instead of the direction passed from foo
.
Legacy behavior
When only field names are provided it falls back to the default sortWhitelist
behavior as before where names will be checked if they exist in the datasource and prefixed with their corresponding alias.
Only in this scenario prefixing is performed. When using mapping it is expected you take care of aliassing yourself.