1. Go to this page and download the library: Download fdevs/pagination 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/ */
fdevs / pagination example snippets
use FDevs\Pagination\Type\ArrayType;
use FDevs\Pagination\Model\CountPagination;
use FDevs\Pagination\Extension\ArrayType\PageExtension;
use FDevs\Pagination\Extension\ArrayType\LimitExtension;
use FDevs\Pagination\Extension\ArrayType\OffsetExtension;
use FDevs\Pagination\Extension\ArrayType\CountExtension;
use FDevs\Pagination\Paginator;
use FDevs\Pagination\Renderer\ClosureRenderer;
$paginator = new Paginator();
$paginator
->addType(new ArrayType(),[PageExtension::class,CountExtension::class])
;
$closureRenderer = new ClosureRenderer(function($data) use ($template) {return $twig->render($template, $data);});
$pagination = $paginator->paginate(['a', 'b', 'c'], ['limit' => 1, 'page' => 2], new CountPagination());
$closureRenderer->render($pagination);
namespace App\Pagination\Type;
use FDevs\Pagination\Model\PaginationInterface;
class PDOType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function paginate($target, PaginationInterface $pagination, array $options)
{
//your logic
//$pagination->setItems($target->fetchAll());
return $pagination;
}
/**
* {@inheritdoc}
*/
public function support($target)
{
return $target instanceof \PDOStatement;
}
}
namespace App\Pagination\Extension\PDO;
use FDevs\Pagination\Extension\AbstractExtension;
use FDevs\Pagination\Model\CountPaginationInterface;
use FDevs\Pagination\Model\PaginationInterface;
class CountExtension extends AbstractExtension
{
/**
* {@inheritdoc}
*/
public function supportPagination(PaginationInterface $pagination)
{
return $pagination instanceof CountPaginationInterface;
}
/**
* {@inheritdoc}
*/
public function prepareTarget($target, array $options, PaginationInterface $pagination)
{
/* @var $pagination CountPaginationInterface */
$pagination->setCount($target->rowCount());
return $target;
}
}