A Phalcon paginator adapter for Phalcon Collections

Overview

Phalcon Collection Paginator

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

Why create this?

Being familiar with the various Pagination data adapters available to the Phalcon\Mvc\Model, I expected to see similar adapters for Phalcon\Mvc\Collection. This project is to provide a pagination data adapter for ODM in Phalcon.

Installation

  1. Use composer
  2. Run
    composer require angelxmoreno/phalcon-collection-paginator
  3. Make sure to include Composer's autoload.php file as part of your bootstrapping process
    require 'vendor/autoload.php';

Configuration

Property Description Optional Default
limit The number of items to fetch at a time yes 30
page The current page set to fetch yes 1
collection The collection class' FQN to use for fetching no none
find_query An array to use when building the query for the page set. Must be a find() compatible array. yes []

Example

<?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() returns an \stdClass.

Running tests

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

Contributing

  1. Fork the repo
  2. Branch from master
  3. Open a PR

License

(The MIT license)

Copyright (c) 2017 Angel S. Moreno

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

You might also like...
A composer package designed to help you create a JSON:API in Phalcon
A composer package designed to help you create a JSON:API in Phalcon

phalcon-json-api-package A composer package designed to help you create a JSON:API in Phalcon What happens when a PHP developer wants to create an API

Setupify is a Phalcon provisioning and development tool.
Setupify is a Phalcon provisioning and development tool.

Setupify Provisioning Tool WARNING: Setupify is currently in a state of experimentation. Use tag release. Setupify is a collection of bash scripts for

RedisPlugin for Phalcon

RedisPlugin for Phalcon (The correspondence of MySQL sharding.) Composer { "require": { "ienaga/phalcon-redis-plugin": "3.*" } } Versio

Easy Repository pattern for PHP Phalcon framework.

Phalcon Repositories Introduction Phalcon Repositories lets you easily build repositories for your Phalcon models, for both SQL and Mongo drivers. PHP

Phalcon devtools

Yarak yarak - (Falconry) a state of prime fitness in a falcon Laravel inspired Phalcon devtools Database migrations that rollback step-by-step, reset

Incubator adapters/functionality for the Phalcon PHP Framework

Phalcon Incubator This is a repository to publish/share/experiment with new adapters, prototypes or functionality that can potentially be incorporated

PHP Profiler & Developer Toolbar (built for Phalcon)
PHP Profiler & Developer Toolbar (built for Phalcon)

Prophiler - A PHP Profiler & Developer Toolbar built for Phalcon Demo The demo website has been moved to a separate repository: https://github.com/fab

A powerful debug and profilers tool for the Phalcon Framework
A powerful debug and profilers tool for the Phalcon Framework

Phalcon Debugbar Integrates PHP Debug Bar with Phalcon Framework. 中文说明 Features Normal request capturing Ajax request capturing Redirect request chain

Phalcon 3.x BB Debugger Strong and easy install.
Phalcon 3.x BB Debugger Strong and easy install.

Phalcon BB Debugger Phalcon Version: 3.x BB Debugger Version: 1.0.3 Change Log See ChangeLog What is BB Debugger ? The bb debugger, written for the ph

Releases(v1.0.0)
Owner
Angel S. Moreno
Angel S. Moreno
This Repo is a storage of Postman collections for Magento

Magento Postman repository This Repository is a storage of Postman collections for Magento. If you have what to share, you are welcome to contribute a

Lyzun Oleksandr 14 May 17, 2022
JsonCollectionParser - Event-based parser for large JSON collections (consumes small amount of memory)

Event-based parser for large JSON collections (consumes small amount of memory). Built on top of JSON Streaming Parser This packa

Max Grigorian 113 Dec 6, 2022
QuidPHP/Main is a PHP library that provides a set of base objects and collections that can be extended to build something more specific.

QuidPHP/Main is a PHP library that provides a set of base objects and collections that can be extended to build something more specific. It is part of the QuidPHP package and can also be used standalone.

QuidPHP 4 Jul 2, 2022
Provides an object-oriented API to query in-memory collections in a SQL-style.

POQ - PHP Object Query Install composer require alexandre-daubois/poq 1.0.0-beta2 That's it, ready to go! ?? Usage Here is the set of data we're going

Alexandre Daubois 16 Nov 29, 2022
An Inertia.js adapter for Statamic.

Inertia.js adapter for Statamic Statamic server side adapter for Inertia.js to build single-page apps, without building an API. Installation You can i

Adam Campbell 52 Dec 31, 2022
Doctrine adapter for SlmQueue module

SlmQueueDoctrine Created by Stefan Kleff Requirements SlmQueue Doctrine 2 ORM Module or roave/psr-container-doctrine Note: it's necessary require the

Webador 32 May 13, 2022
Phalcon Demo Application

Phalcon Demo Application We use modified Phalcon INVO Application to demonstrate basics of Codeception testing. We expect to implement as many feature

Codeception Testing Framework 42 Oct 7, 2022
Phalcon official Forum

Phosphorum 3 Phosphorum is an engine for building flexible, clear and fast forums. You can adapt it to your own needs or improve it if you want. Pleas

The Phalcon PHP Framework 361 Dec 27, 2022
Phalcon PHP Meta tags Service

About Phalcon meta tags plugin for PhalconPHP. This plugin allows you to easily and flexibly customize the meta tags of your view. If this plugin help

null 12 Oct 7, 2022
Implementation of an API application using the Phalcon Framework

phalcon-api Sample API using Phalcon Implementation of an API application using the Phalcon Framework https://phalcon.io Installation Clone the projec

The Phalcon PHP Framework 81 Dec 15, 2022