Permalink
Browse files

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 f8d63f86a213a00e963a954eca5bccbfd10c39b2 @javiereguiluz javiereguiluz committed Apr 3, 2016
View
@@ -8,3 +8,4 @@
/vendor/
/bin/
/composer.phar
+web/bundles/whiteoctoberpagerfanta
View
@@ -20,7 +20,7 @@ public function registerBundles()
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
- new Knp\Bundle\PaginatorBundle\KnpPaginatorBundle(),
+ new WhiteOctober\PagerfantaBundle\WhiteOctoberPagerfantaBundle(),
new CodeExplorerBundle\CodeExplorerBundle(),
new AppBundle\AppBundle(),
new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(),
@@ -18,7 +18,7 @@
{% endfor %}
<div class="navigation text-center">
- {{ knp_pagination_render(posts) }}
+ {{ pagerfanta(posts, 'twitter_bootstrap3', { routeName: 'blog_index_paginated' }) }}
</div>
{% endblock %}
@@ -90,8 +90,3 @@ swiftmailer:
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
-
-# KnpPaginatorBundle configuration (used to paginate large result set)
-knp_paginator:
- template:
- pagination: KnpPaginatorBundle:Pagination:twitter_bootstrap_v3_pagination.html.twig
View
@@ -17,7 +17,6 @@
"ezyang/htmlpurifier" : "~4.7",
"incenteev/composer-parameter-handler" : "~2.1",
"ircmaxell/password-compat" : "~1.0",
- "knplabs/knp-paginator-bundle" : "~2.4",
"leafo/scssphp" : "^0.4.0",
"patchwork/jsqueeze" : "~1.0",
"sensio/distribution-bundle" : "~5.0",
@@ -26,7 +25,8 @@
"symfony/monolog-bundle" : "~2.7",
"symfony/swiftmailer-bundle" : "~2.3",
"symfony/symfony" : "~2.8",
- "twig/extensions" : "~1.2"
+ "twig/extensions" : "~1.2",
+ "white-october/pagerfanta-bundle" : "^1.0"
},
"require-dev": {
"sensio/generator-bundle": "~3.0"
View
@@ -4,8 +4,8 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
- "hash": "3508c28d92f3e0d6201c480a38a58bf0",
- "content-hash": "439bca1c722383b01586454a44ed24d0",
+ "hash": "b4c51be02d719000805fe15a7b930d35",
+ "content-hash": "2d6d608b660cea6c5520c9431b4ffead",
"packages": [
{
"name": "doctrine/annotations",
@@ -1057,135 +1057,6 @@
"time": "2014-01-12 16:20:24"
},
{
- "name": "knplabs/knp-components",
- "version": "1.3.2",
- "source": {
- "type": "git",
- "url": "https://github.com/KnpLabs/knp-components.git",
- "reference": "4503275e4f1a0e9667aa65b0ebed842ef2d8d8ba"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/KnpLabs/knp-components/zipball/4503275e4f1a0e9667aa65b0ebed842ef2d8d8ba",
- "reference": "4503275e4f1a0e9667aa65b0ebed842ef2d8d8ba",
- "shasum": ""
- },
- "require": {
- "php": ">=5.3.2"
- },
- "require-dev": {
- "doctrine/mongodb-odm": "~1.0@beta",
- "doctrine/orm": "~2.4",
- "phpunit/phpunit": "~4.2",
- "ruflin/elastica": "~1.0",
- "symfony/event-dispatcher": "~2.5"
- },
- "suggest": {
- "doctrine/common": "to allow usage pagination with Doctrine ArrayCollection",
- "doctrine/mongodb-odm": "to allow usage pagination with Doctrine ODM MongoDB",
- "doctrine/orm": "to allow usage pagination with Doctrine ORM",
- "propel/propel1": "to allow usage pagination with Propel ORM",
- "ruflin/Elastica": "to allow usage pagination with ElasticSearch Client",
- "solarium/solarium": "to allow usage pagination with Solarium Client"
- },
- "type": "library",
- "extra": {
- "branch-alias": {
- "dev-master": "1.3.x-dev"
- }
- },
- "autoload": {
- "psr-0": {
- "Knp\\Component": "src"
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
- {
- "name": "KnpLabs Team",
- "homepage": "http://knplabs.com"
- },
- {
- "name": "Symfony Community",
- "homepage": "http://github.com/KnpLabs/knp-components/contributors"
- }
- ],
- "description": "Knplabs component library",
- "homepage": "http://github.com/KnpLabs/knp-components",
- "keywords": [
- "components",
- "knp",
- "knplabs",
- "pager",
- "paginator"
- ],
- "time": "2015-09-01 10:54:53"
- },
- {
- "name": "knplabs/knp-paginator-bundle",
- "version": "2.5.1",
- "source": {
- "type": "git",
- "url": "https://github.com/KnpLabs/KnpPaginatorBundle.git",
- "reference": "5147740faff4d32e6f42acf64475314c35320fa4"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/KnpLabs/KnpPaginatorBundle/zipball/5147740faff4d32e6f42acf64475314c35320fa4",
- "reference": "5147740faff4d32e6f42acf64475314c35320fa4",
- "shasum": ""
- },
- "require": {
- "knplabs/knp-components": "~1.2",
- "php": ">=5.3.3",
- "symfony/framework-bundle": "~2.3|~3.0",
- "twig/twig": "~1.12|~2"
- },
- "require-dev": {
- "symfony/expression-language": "~2.4|~3.0"
- },
- "type": "symfony-bundle",
- "extra": {
- "branch-alias": {
- "dev-master": "2.4.x-dev"
- }
- },
- "autoload": {
- "psr-4": {
- "Knp\\Bundle\\PaginatorBundle\\": ""
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
- {
- "name": "KnpLabs Team",
- "homepage": "http://knplabs.com"
- },
- {
- "name": "Symfony2 Community",
- "homepage": "http://github.com/KnpLabs/KnpPaginatorBundle/contributors"
- }
- ],
- "description": "Paginator bundle for Symfony2 to automate pagination and simplify sorting and other features",
- "homepage": "http://github.com/KnpLabs/KnpPaginatorBundle",
- "keywords": [
- "Symfony2",
- "bundle",
- "knp",
- "knplabs",
- "pager",
- "pagination",
- "paginator"
- ],
- "time": "2015-11-23 17:51:40"
- },
- {
"name": "kriswallsmith/assetic",
"version": "v1.3.2",
"source": {
@@ -1397,6 +1268,73 @@
"time": "2016-03-13 16:08:35"
},
{
+ "name": "pagerfanta/pagerfanta",
+ "version": "v1.0.3",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/whiteoctober/Pagerfanta.git",
+ "reference": "a874d3612d954dcbbb49e5ffe178890918fb76fb"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/whiteoctober/Pagerfanta/zipball/a874d3612d954dcbbb49e5ffe178890918fb76fb",
+ "reference": "a874d3612d954dcbbb49e5ffe178890918fb76fb",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.0"
+ },
+ "require-dev": {
+ "doctrine/orm": "~2.3",
+ "doctrine/phpcr-odm": "1.*",
+ "jackalope/jackalope-doctrine-dbal": "1.*",
+ "jmikola/geojson": "~1.0",
+ "mandango/mandango": "~1.0@dev",
+ "mandango/mondator": "~1.0@dev",
+ "phpunit/phpunit": "~4",
+ "propel/propel1": "~1.6",
+ "ruflin/elastica": "~1.3",
+ "solarium/solarium": "~3.1"
+ },
+ "suggest": {
+ "doctrine/mongodb-odm": "To use the DoctrineODMMongoDBAdapter.",
+ "doctrine/orm": "To use the DoctrineORMAdapter.",
+ "doctrine/phpcr-odm": "To use the DoctrineODMPhpcrAdapter. >= 1.1.0",
+ "mandango/mandango": "To use the MandangoAdapter.",
+ "propel/propel1": "To use the PropelAdapter",
+ "solarium/solarium": "To use the SolariumAdapter."
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.0.x-dev"
+ }
+ },
+ "autoload": {
+ "psr-0": {
+ "Pagerfanta\\": "src/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Pablo Díez",
+ "email": "pablodip@gmail.com"
+ }
+ ],
+ "description": "Pagination for PHP 5.3",
+ "keywords": [
+ "page",
+ "pagination",
+ "paginator",
+ "paging"
+ ],
+ "time": "2014-10-06 10:57:25"
+ },
+ {
"name": "paragonie/random_compat",
"version": "v1.4.1",
"source": {
@@ -2676,6 +2614,58 @@
"templating"
],
"time": "2016-01-25 21:22:18"
+ },
+ {
+ "name": "white-october/pagerfanta-bundle",
+ "version": "v1.0.6",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/whiteoctober/WhiteOctoberPagerfantaBundle.git",
+ "reference": "ada62843d9ba0d3aa61d0dcc7becdb25a2e2f545"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/whiteoctober/WhiteOctoberPagerfantaBundle/zipball/ada62843d9ba0d3aa61d0dcc7becdb25a2e2f545",
+ "reference": "ada62843d9ba0d3aa61d0dcc7becdb25a2e2f545",
+ "shasum": ""
+ },
+ "require": {
+ "pagerfanta/pagerfanta": "1.0.*",
+ "symfony/framework-bundle": "~2.3|~3.0",
+ "symfony/property-access": "~2.3|~3.0",
+ "symfony/twig-bundle": "~2.3|~3.0"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "~3.7",
+ "symfony/symfony": "~2.3|~3.0"
+ },
+ "type": "symfony-bundle",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.0.x-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "WhiteOctober\\PagerfantaBundle\\": ""
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Pablo Díez",
+ "email": "pablodip@gmail.com"
+ }
+ ],
+ "description": "Bundle to use Pagerfanta with Symfony2",
+ "keywords": [
+ "page",
+ "paging"
+ ],
+ "time": "2016-03-16 19:24:56"
}
],
"packages-dev": [
@@ -40,15 +40,7 @@ class BlogController extends Controller
*/
public function indexAction($page)
{
- $query = $this->getDoctrine()->getRepository('AppBundle:Post')->queryLatest();
-
- $paginator = $this->get('knp_paginator');
- $posts = $paginator->paginate($query, $page, Post::NUM_ITEMS);
- $posts->setUsedRoute('blog_index_paginated');
-
- if (0 === count($posts) && 1 < $page) {
- throw $this->createNotFoundException();
- }
+ $posts = $this->getDoctrine()->getRepository('AppBundle:Post')->findLatest($page);
return $this->render('blog/index.html.twig', array('posts' => $posts));
}
@@ -11,7 +11,11 @@
namespace AppBundle\Repository;
+use AppBundle\Entity\Post;
use Doctrine\ORM\EntityRepository;
+use Doctrine\ORM\Query;
+use Pagerfanta\Adapter\DoctrineORMAdapter;
+use Pagerfanta\Pagerfanta;
/**
* This custom Doctrine repository contains some methods which are useful when
@@ -23,6 +27,9 @@
*/
class PostRepository extends EntityRepository
{
+ /**
+ * @return Query
+ */
public function queryLatest()
{
return $this->getEntityManager()
@@ -36,8 +43,17 @@ public function queryLatest()
;
}
- public function findLatest()
+ /**
+ * @param int $page
+ *
+ * @return Pagerfanta
+ */
+ public function findLatest($page = 1)
{
- $this->queryLatest()->getResult();
+ $paginator = new Pagerfanta(new DoctrineORMAdapter($this->queryLatest(), false));
+ $paginator->setMaxPerPage(Post::NUM_ITEMS);
+ $paginator->setCurrentPage($page);
+
+ return $paginator;
}
}

0 comments on commit f8d63f8

Please sign in to comment.