Skip to content

Commit f8d63f8

Browse files
committed
feature #328 Replaced KnpPaginator by PagerFanta (javiereguiluz)
This PR was squashed before being merged into the master branch (closes #328). Discussion ---------- Replaced KnpPaginator by PagerFanta This fixes #305. Commits ------- df26404 Replaced KnpPaginator by PagerFanta
2 parents a3bad6b + df26404 commit f8d63f8

File tree

8 files changed

+145
-151
lines changed

8 files changed

+145
-151
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
/vendor/
99
/bin/
1010
/composer.phar
11+
web/bundles/whiteoctoberpagerfanta

app/AppKernel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function registerBundles()
2020
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
2121
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
2222
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
23-
new Knp\Bundle\PaginatorBundle\KnpPaginatorBundle(),
23+
new WhiteOctober\PagerfantaBundle\WhiteOctoberPagerfantaBundle(),
2424
new CodeExplorerBundle\CodeExplorerBundle(),
2525
new AppBundle\AppBundle(),
2626
new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(),

app/Resources/views/blog/index.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
{% endfor %}
1919

2020
<div class="navigation text-center">
21-
{{ knp_pagination_render(posts) }}
21+
{{ pagerfanta(posts, 'twitter_bootstrap3', { routeName: 'blog_index_paginated' }) }}
2222
</div>
2323
{% endblock %}
2424

app/config/config.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,3 @@ swiftmailer:
9090
username: "%mailer_user%"
9191
password: "%mailer_password%"
9292
spool: { type: memory }
93-
94-
# KnpPaginatorBundle configuration (used to paginate large result set)
95-
knp_paginator:
96-
template:
97-
pagination: KnpPaginatorBundle:Pagination:twitter_bootstrap_v3_pagination.html.twig

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
"ezyang/htmlpurifier" : "~4.7",
1818
"incenteev/composer-parameter-handler" : "~2.1",
1919
"ircmaxell/password-compat" : "~1.0",
20-
"knplabs/knp-paginator-bundle" : "~2.4",
2120
"leafo/scssphp" : "^0.4.0",
2221
"patchwork/jsqueeze" : "~1.0",
2322
"sensio/distribution-bundle" : "~5.0",
@@ -26,7 +25,8 @@
2625
"symfony/monolog-bundle" : "~2.7",
2726
"symfony/swiftmailer-bundle" : "~2.3",
2827
"symfony/symfony" : "~2.8",
29-
"twig/extensions" : "~1.2"
28+
"twig/extensions" : "~1.2",
29+
"white-october/pagerfanta-bundle" : "^1.0"
3030
},
3131
"require-dev": {
3232
"sensio/generator-bundle": "~3.0"

composer.lock

Lines changed: 121 additions & 131 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/AppBundle/Controller/BlogController.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,7 @@ class BlogController extends Controller
4040
*/
4141
public function indexAction($page)
4242
{
43-
$query = $this->getDoctrine()->getRepository('AppBundle:Post')->queryLatest();
44-
45-
$paginator = $this->get('knp_paginator');
46-
$posts = $paginator->paginate($query, $page, Post::NUM_ITEMS);
47-
$posts->setUsedRoute('blog_index_paginated');
48-
49-
if (0 === count($posts) && 1 < $page) {
50-
throw $this->createNotFoundException();
51-
}
43+
$posts = $this->getDoctrine()->getRepository('AppBundle:Post')->findLatest($page);
5244

5345
return $this->render('blog/index.html.twig', array('posts' => $posts));
5446
}

src/AppBundle/Repository/PostRepository.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111

1212
namespace AppBundle\Repository;
1313

14+
use AppBundle\Entity\Post;
1415
use Doctrine\ORM\EntityRepository;
16+
use Doctrine\ORM\Query;
17+
use Pagerfanta\Adapter\DoctrineORMAdapter;
18+
use Pagerfanta\Pagerfanta;
1519

1620
/**
1721
* This custom Doctrine repository contains some methods which are useful when
@@ -23,6 +27,9 @@
2327
*/
2428
class PostRepository extends EntityRepository
2529
{
30+
/**
31+
* @return Query
32+
*/
2633
public function queryLatest()
2734
{
2835
return $this->getEntityManager()
@@ -36,8 +43,17 @@ public function queryLatest()
3643
;
3744
}
3845

39-
public function findLatest()
46+
/**
47+
* @param int $page
48+
*
49+
* @return Pagerfanta
50+
*/
51+
public function findLatest($page = 1)
4052
{
41-
$this->queryLatest()->getResult();
53+
$paginator = new Pagerfanta(new DoctrineORMAdapter($this->queryLatest(), false));
54+
$paginator->setMaxPerPage(Post::NUM_ITEMS);
55+
$paginator->setCurrentPage($page);
56+
57+
return $paginator;
4258
}
4359
}

0 commit comments

Comments
 (0)