Doctrine2 Paginator [英] Doctrine2 Paginator

查看:122
本文介绍了Doctrine2 Paginator的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从2.2版开始,Doctrine有 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";
}

这个类中没有什么新的,因为文档中描述的整个过程可以使用 $ query-> getResult()

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

我知道有一些关于分页的包,但是不想安装第三方捆绑包这样的琐碎问题。另一方面,我找不到任何关于教条分页的分页2。应该有一些有用的类的方法。我在哪里可以找到他们?如果没有,那么整个班级的意义是什么?

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?

推荐答案

教条的分析者不是Symfony意识到的 - 它是低级别和

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

另一方面,如果您安装第三方捆绑,您将获得Doctrine ORM& ODM,Propel,plain数组等。您还将获得Symfony的集成和查看助手。至少 WhiteOctoberPagerfantaBundle ,我使用的都是这些。

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.

所以,除非你只去Doctrine,我建议你重新考虑你对第三方束的位置。

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

这篇关于Doctrine2 Paginator的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆