dwalczyk/paginator-bundle
Composer 安装命令:
composer require dwalczyk/paginator-bundle
包简介
Symfony bundle for paginate
README 文档
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!
统计信息
- 总下载量: 378
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-03-08