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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With