dwalczyk / paginator-bundle
Symfony bundle for paginate
Installs: 371
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: ^8.2
- doctrine/orm: ^2.11
- symfony/framework-bundle: ^6.0|^7.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.13
- phpstan/phpstan: ^1.10
- spaze/phpstan-disallowed-calls: ^2.16
This package is auto-updated.
Last update: 2024-10-30 01:53:57 UTC
README
Paginator Bundle for the Symfony Framework.
Installation
Composer
composer require dwalczyk/paginator-bundle
Add bundle to application
// config/bundles.php DWalczyk\Paginator\PaginatorBundle::class => ['all' => true]
Usage
Base usage
Doctrine QueryBuilder is supported by default.
use DWalczyk\Paginator\PaginatorInterface; #[Route('/users')] public function __invoke(PaginatorInterface $paginator) { $res = $paginator->paginate( $target = $this->getEm()->createQueryBuilder()->select('u')->from(User::class, 'u'), $page = 1, $itemsPerPage = 30 ); dump($res); }
Custom data loader
- Create class that implements DWalczyk\Paginator\DataLoaderInterface
<?php namespace App\Service; use DWalczyk\Paginator\DataLoaderInterface; class SamplePaginatorDataLoader implements DataLoaderInterface { public function loadItems(mixed $target, int $offset, int $limit): array { // some logic here } public function loadTotalCount(mixed $target): int { // some logic here } }
- Replace default data loader (doctrine QueryBuilder) with your new data loader.
# config/services.yaml services: ... DWalczyk\Paginator\DataLoaderInterface: '@App\Service\SamplePaginatorDataLoader'
- done!