gpslab / pagination-bundle
分页包
v1.4.2
2020-03-19 18:07 UTC
Requires
- php: >=5.4.0
- doctrine/orm: ~2.4|~2.5|~2.6
- sensio/framework-extra-bundle: ~3.0|~4.0|~5.0
- symfony/config: ~2.3|~3.0|~4.0|~5.0
- symfony/dependency-injection: ~2.3|~3.0|~4.0|~5.0
- symfony/expression-language: ~2.3|~3.0|~4.0|~5.0
- symfony/http-kernel: ~2.3|~3.0|~4.0|~5.0
- symfony/routing: ~2.3|~3.0|~4.0|~5.0
- symfony/yaml: ~2.3|~3.0|~4.0|~5.0
- twig/twig: ^1.34|^2.0|^3.0
Requires (Dev)
- phpunit/phpunit: ^4.8.36
README
PaginationBundle
安装
使用Composer(https://packagist.org.cn)非常简单,运行
composer req gpslab/pagination-bundle
配置
默认配置
gpslab_pagination: # Page range used in pagination control max_navigate: 5 # Name of URL parameter for page number parameter_name: 'page' # Sliding pagination controls template template: 'GpsLabPaginationBundle::pagination.html.twig'
简单用法
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 ]); } }
在模板中显示分页
<nav class="pagination"> {{- pagination_render(pagination) -}} </nav>
文档
许可证
此包受MIT许可证保护。完整的许可证请见文件:LICENSE