PHP code example of angelxmoreno / phalcon-collection-paginator
1. Go to this page and download the library: Download angelxmoreno/phalcon-collection-paginator library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
angelxmoreno / phalcon-collection-paginator example snippets
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();
bash