Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Doctrine2 Paginator

Starting with version 2.2 Doctrine has Paginator. There is only one example in the documentation:

<?php
use Doctrine\ORM\Tools\Pagination\Paginator;

$dql = "SELECT p, c FROM BlogPost p JOIN p.comments c";
$query = $entityManager->createQuery($dql)
                       ->setFirstResult(0)
                       ->setMaxResults(100);

$paginator = new Paginator($query, $fetchJoin = true);

$c = count($paginator);
foreach ($paginator as $post) {
    echo $post->getHeadline() . "\n";
}

There is nothing new in this class since the whole process described in the documentation can be done with $query->getResult().

I know there are some bundles about pagination but I don't want to install third party bundles for such trivial issues. On the other hand, I cannot find anything about pagination of doctrine2. There should be some useful methods of the class. Where can I find them? If there are not then what is the point of the whole class?

like image 200
seferov Avatar asked Apr 11 '12 13:04

seferov


1 Answers

Doctrine's paginator is not Symfony aware — it's low-level and Doctrine specific.

On the other hand, if you install a 3rd party bundle, you'll get pagination adapters for Doctrine ORM & ODM, Propel, plain arrays, etc. You'll also get Symfony integration and view helpers. At least WhiteOctoberPagerfantaBundle that I use does all these.

So, unless you're going with Doctrine only, I suggest you reconsider your position about a 3rd party bundle.

like image 89
Elnur Abdurrakhimov Avatar answered Nov 12 '22 08:11

Elnur Abdurrakhimov