dezull / dbal-paginator-service-provider
A Doctrine DBAL paginator provider for Silex, based on knp pager components and knp-paginator-bundle.
Installs: 1 169
Dependents: 0
Suggesters: 0
Security: 0
Stars: 6
Watchers: 2
Forks: 4
Open Issues: 0
Requires
- php: >=5.3.0
- doctrine/dbal: ~2.2
- knplabs/knp-paginator-bundle: 2.3.*
This package is not auto-updated.
Last update: 2025-03-24 17:42:45 UTC
README
Based on KnpLabs' PaginatorBundle.
Installation
Add to composer.json
{ "require": { "dezull/dbal-paginator-service-provider": "dev-master" } }
Usage
- When registering
TwigServiceProvider
, add the paginator's template path (create your own or just use KnpPaginatorBundle's).
$app->register(new Silex\Provider\TwigServiceProvider(), array( 'twig.path' => array( /* Your other templates */ __DIR__.'/../vendor/knplabs/knp-paginator-bundle/Knp/Bundle/PaginatorBundle/Resources/views', ), ));
- Register
DBALPaginatorServiceProvider
.
$app->register(new Dezull\Silex\Provider\DBALPaginatorServiceProvider\DBALPaginatorServiceProvider(), array( /* The following assumes you use the template path as in step #1 */ 'dezull.dbal_paginator.template.pagination' => 'Pagination/twitter_bootstrap_pagination.html.twig', 'dezull.dbal_paginator.template.sortable' => 'Pagination/sortable_link.html.twig', ));
- In your controller
public function indexAction(Request $request, Application $app) { $page = (int) $request->query->get('page', 1); $sortKey = $request->query->get('sort', 's.id'); $direction = $request->query->get('direction', 'desc'); /* Doctrine DBAL QueryBuilder */ $qb = $app['db']->createQueryBuilder() ->select('s.*') ->from('sometable', 's') ->orderBy($sortKey, $direction); $pagination = $app['dezull.dbal_paginator']->paginate( $qb, $page, 20 /* per page limit */ ); return $app['twig']->render('Foo/index.html.twig', array( 'pagination' => $pagination, )); }
- To render the pagination in the template
{{ dezull_dbal_pagination_render(pagination) }}
TODO
- Remove dependency on KnpPaginatorBundle