在教义2中的分页,ZF2

时间:2014-03-25 11:42:50

标签: php doctrine-orm pagination doctrine zend-framework2

我正在尝试使用最新版本的Doctrine实现分页: https://doctrine-orm.readthedocs.org/en/latest/tutorials/pagination.html?highlight=doctrine%20dql%20pagination

$query = $this->getEntityManager()->createQuery('
        SELECT b,pb
        FROM BookApi\Entity\Book b
        LEFT JOIN b.publisher pb        
        ')->setFirstResult(0)->setMaxResults(10);
$paginator = new Paginator($query, $fetchJoinCollection = true);    
$this->totalResults = count($paginator);

计数我与paginator一起返回是正确的。 但是getQuery并没有给我十个结果。它返回5.

$output = $paginator->getQuery()->getArrayResult();

这是错误的方法吗?

1 个答案:

答案 0 :(得分:1)

根据上述评论,这对我有用。 我不得不添加补水模式

$book = $this->getEntityManager()->createQuery('
     SELECT b,pb
     FROM BookApi\Entity\Book b
     LEFT JOIN b.publisher pb   
')->setHydrationMode(\Doctrine\ORM\AbstractQuery::HYDRATE_ARRAY);

$paginator = new Paginator(
     new DoctrinePaginator(new ORMPaginator($book))
);

$paginator
        ->setCurrentPageNumber(0)
        ->setItemCountPerPage(10);