简体   繁体   中英

Pagination In Doctrine 2, ZF2

I am trying to implement pagination, using the latest version of 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);

The count I get returned with the paginator is correct. However the getQuery does not give me ten results. It returns 5.

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

Is this the wrong approach?

Based on the comment above, this worked for me. I had to add the hydration mode

$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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM