PHP code example of alexello / phalcon-mongodb-pagination-adapter
1. Go to this page and download the library: Download alexello/phalcon-mongodb-pagination-adapter 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/ */
alexello / phalcon-mongodb-pagination-adapter example snippets
// Current page to show
// In a controller this can be:
// $this->request->getQuery('page', 'int'); // GET
// $this->request->getPost('page', 'int'); // POST
$currentPage = (int) $_GET["page"];
// The data set to paginate
$robots = $DB->selectCollection('robots')->find();
// Create a Model paginator, show 10 rows by page starting from $currentPage
$paginator = new \AlexEllo\Phalcon\MongoDB\Pagination\Adapter\MongoCursor(
array(
"data" => $robots,
"limit"=> 10,
"page" => $currentPage
)
);
// Get the paginated results
$page = $paginator->getPaginate();