josbeir/cakephp-paginator-sortmap 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

josbeir/cakephp-paginator-sortmap

Composer 安装命令:

composer require josbeir/cakephp-paginator-sortmap

包简介

Paginator with support for custom mappable multi sortable sort keys

README 文档

README

Software License Build Status

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

<?php
namespace App\Controller;

class FooController extends AppController
{    
    public function initialize()
    {
        parent::initialize();
        
        $this->loadComponent('Josbeir/Paginator.Paginator');
    }
    
    public function index()
    {
        $paginate = [
            'sortMap' => [
                'name' => 'name',
                'modified' => [ 'modified', 'name' ]
            ]
        ];
        
        // paginate FooTable
        $results = $this->Paginator->paginate($this->Foo, $paginate);
    }
}

Mapping sort => field

In its simplest form you can just use the sortMap to rename sort keys:

[
    'sortMap' => [
        'foo' => 'bar'
    ]
]

Will result in sort order

[ 'bar' => 'asc' ]

Mapping multiple fields under one sort

A mapping can also consist of multiple sort fields grouped together:

[
    'sortMap' => [
        'foo' => [
            'Article.name',
            'Article.created'
        ]
    ]
]

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'

Article.name' => asc
Article.created' => asc

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.

[
    'sortMap' => [
        'foo' => [
            'Article.name',
            'Article.created' => 'asc'
        ]
    ]
]

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.

[
    'sortMap' => [
        'name',
        'created'
    ]
]

统计信息

  • 总下载量: 342
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-07-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固