Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ecedi/pager-bundle
An old pager bundle pre KnpPaginatorBundle
https://github.com/ecedi/pager-bundle
ecedi knppaginatorbundle pager-bundle php
Last synced: 1 day ago
JSON representation
An old pager bundle pre KnpPaginatorBundle
- Host: GitHub
- URL: https://github.com/ecedi/pager-bundle
- Owner: ecedi
- License: mit
- Created: 2014-09-04T14:28:36.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-09-10T13:40:08.000Z (over 10 years ago)
- Last Synced: 2024-11-08T23:37:56.918Z (about 2 months ago)
- Topics: ecedi, knppaginatorbundle, pager-bundle, php
- Language: PHP
- Homepage: https://www.ecedi.fr
- Size: 160 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# ecedi/pager-bundle by [Agence Ecedi](http://ecedi.fr)
This is a very old pager helper implementation. It predate [KnpPaginatorBundle](https://github.com/KnpLabs/KnpPaginatorBundle) which is our prefered pager bundle thoses days
## installation
### edit your composer.json file and add
```json
{
"require": {
"ecedi/pager-bundle": "dev-master",
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/ecedi/pager-bundle"
}
]
}
```### Add VarsBundle to your application kernel
```php
// app/AppKernel.php
public function registerBundles()
{
return array(
// ...
new Ecedi\PagerBundle\EcediPagerBundle(),
// ...
);
}
```## Usage
in a controller
```php
class MyController extends Controller {
public function indexAction(Request $request) {
// get pagination GET parameters from $ruest
$pager = $this->get('ecedi.pager');
$pager->setDefaultLimit(10);
$pager->bind($request->query);// get a QueryBuilder
$qb = $this->getDoctrine()->getManager()->getRepository('MyBundle:Myentity')->findAllByName(); //it returns a QueryBuilder, not a Query$qb
->setMaxResults($pager->getLimit())
->setFirstResult($pager->getOffset())
;
$query = $qb->getQuery();
$entitites = $query->getResult();// pagination
$pager->setCount($count); //you have to manully run another query to find out the nbr of results
$pager->setCurrentCount(count($entities));
$pager->setArgs(array()); //this is an array of the route parameters to build urls in twig templatereturn array(
'entities' => $entities,
'pager' => $pager,
);
}
}
```in a view
```jinja
{% include 'EcediPagerBundle:pager:prevnext.html.twig' with {'pager': page, 'route': 'a_route_name', 'anchor': 'an_anchor'} %}
```