skoziel / silex-pagination
Silex 2.0的简单分页服务提供商
1.0.1
2016-10-08 13:48 UTC
Requires
- php: >=5.6
- amstaffix/pagination: ~1.1
Requires (Dev)
- silex/silex: >=2.0
- twig/twig: ~1.8
This package is auto-updated.
Last update: 2024-09-12 19:12:12 UTC
README
此服务提供商基于AmsTaFFix/silex-pagination,但现在适用于Silex 2.0。
要求
- silex/silex >= 2.0
- kilte/pagination >= 1.1
- twig/twig >= 1.8
- PHP >= 5.6
注册
$app->register(new SKoziel\Silex\Pagination\PaginationServiceProvider(), array( 'pagination.per_page' => 30, //Number of items per page, default = 20 'pagination.neighbours' => 5 //Number of neighboring pages, default = 4 ));
特质
use SKoziel\Silex\Pagination\PaginationTrait; $pagination = $app->pagination($total, $current, $perPage, $neighbours);
使用方法
构建分页
$pagination = $app['pagination'](100, 5); $pages = $pagination->build();
创建友好的分页Twig
<ul> {% for number, position in pages %} {% if position == 'first' %} <li><a href="/{{ number }}">«</a></li> {% elseif position == 'less' or position == 'more' %} <li>...</li> {% elseif position == 'previous' or position == 'next' %} <li><a href="/{{ number }}">{{ number }}</a></li> {% elseif position == 'current' %} <li>{{ number }}</li> {% elseif position == 'last' %} <li><a href="/{{ number }}">»</a></li> {% endif %} {% endfor %} </ul>
渲染带有分页的Twig
$app['twig']->render('pagination.twig', array('pages' => $pages, 'current' => $pagination->currentPage()));