Doctrine2 分页器 [英] Doctrine2 Paginator

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

问题描述

从 2.2 版开始,Doctrine 有 Paginator.文档中只有一个示例:

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

<?php
use DoctrineORMToolsPaginationPaginator;

$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() . "
";
}

这个类没有什么新东西,因为文档中描述的整个过程可以用 $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?

推荐答案

Doctrine 的分页器不支持 Symfony — 它是低级的且特定于 Doctrine.

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

另一方面,如果您安装第 3 方捆绑包,您将获得分页Doctrine ORM & 适配器ODM、Propel、普通数组等.您还将获得 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,否则我建议您重新考虑您对 3rd 方捆绑包的立场.

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

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

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