angelxmoreno/phalcon-collection-paginator

Phalcon Collections 的分页适配器

v1.0.0 2017-09-18 06:27 UTC

This package is auto-updated.

Last update: 2024-09-16 03:42:20 UTC


README

A Phalcon paginator adapter for Phalcon Collections Build Status Codacy Badge Code Climate License

为何创建此项目?

熟悉 Phalcon\Mvc\Model 可用的各种 分页数据适配器,我期望看到为 Phalcon\Mvc\Collection 提供类似适配器。此项目旨在为 Phalcon 中的 ODM 提供分页数据适配器。

安装

  1. 使用 composer
  2. 运行
    composer require angelxmoreno/phalcon-collection-paginator
  3. 确保将 Composer 的 autoload.php 文件包含在您的启动过程中
    require 'vendor/autoload.php';

配置

示例

<?php

use App\Models\Cars;
use Phalcon\Paginator\Adapter\Collection as CollectionPaginator;

// In a controller you could have something like so:

// An array of defaults settings
$default_pagination_settings = [
   'limit' => CollectionPaginator::DEFAULT_LIMIT,
   'page' => 1,
   'collection' => Cars::class,
   'find_query' => [
       'year' => 1980
   ]
];

// Merge the default array with the query string params
$pagination_settings = array_merge($default_pagination_settings, $this->request->getQuery());

// Create a Collection Paginator instance with the pagination settings
$paginator = CollectionPaginator($pagination_settings);

// Get the paginated results \stdClass and set it to the view
$this->view->results = $paginator->getPaginate();

CollectionPaginator->getPaginate() 返回一个 \stdClass

运行测试

docker-comose up
./bin/run_tests.sh
docker-comose down

贡献

  1. 复制存储库
  2. 从 master 分支
  3. 打开 PR

许可证

(MIT 许可证)

版权所有 (c) 2017 Angel S. Moreno

特此授予任何获得本软件及其相关文档副本(“软件”)的个人免费使用该软件的权利,不受任何限制,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或销售软件副本的权利,并允许软件的提供方以任何方式使用该软件,受以下条件约束:

上述版权声明和本许可声明应包含在软件的所有副本或主要部分中。

软件按“原样”提供,不提供任何明示或暗示的保证,包括但不限于适销性、针对特定目的的适用性和非侵权性保证。在任何情况下,作者或版权所有者不对任何索赔、损害或其他责任负责,无论是基于合同、侵权或其他方式,无论是因软件或其使用或其他方式而产生的。