PHP code example of gpslab / pagination-bundle
1. Go to this page and download the library: Download gpslab/pagination-bundle 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/ */
gpslab / pagination-bundle example snippets
use GpsLab\Bundle\PaginationBundle\Service\Configuration;
class ArticleController extends Controller
{
private const ARTICLES_PER_PAGE = 30;
public function index(ArticleRepository $rep, Configuration $pagination): Response
{
$pagination->setTotalPages(ceil($rep->getTotalPublished() / self::ARTICLES_PER_PAGE));
// get articles chunk
$offset = ($pagination->getCurrentPage() - 1) * self::ARTICLES_PER_PAGE;
$articles = $rep->getPublished(self::ARTICLES_PER_PAGE, $offset);
return $this->render('AcmeDemoBundle:Article:index.html.twig', [
'articles' => $articles,
'pagination' => $pagination
]);
}
}