A Phalcon paginator adapter for Phalcon Collections
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.
- Use composer
- Run
composer require angelxmoreno/phalcon-collection-paginator
- Make sure to include Composer's autoload.php file as part of your bootstrapping process
require 'vendor/autoload.php';
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 | [] |
<?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.
docker-comose up
./bin/run_tests.sh
docker-comose down
- Fork the repo
- Branch from master
- Open a PR
(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.