i want to use doctrine with zend_paginator
here some example query :
$allArticleObj = $this->_em->getRepository(\'Articles\'); $qb
I was very surprised how hard it was to find an adapter example that doesn't cause performance issues with large collections for Doctrine 2 and ZF1.
My soultion does use the the Doctrine\ORM\Tools\Pagination\Paginator from Doctrine 2.2 just like @Kurt's answer; however the difference that this will return the doctrine paginator (Which is it's self an \Iterator
) from getItems
without the entire query results being hydrated.
use Doctrine\ORM\Tools\Pagination\Paginator as DoctrinePaginator;
use Doctrine\ORM\Query;
class DoctrinePaginatorAdapter implements \Zend_Paginator_Adapter_Interface
{
protected $query;
public function __construct(Query $query)
{
$this->query = $query;
}
public function count()
{
return $this->createDoctrinePaginator($this->query)->count();
}
public function getItems($offset, $itemCountPerPage)
{
$this->query->setFirstResult($offset)
->setMaxResults($itemCountPerPage);
return $this->createDoctrinePaginator($this->query);
}
protected function createDoctrinePaginator(Query $query, $isFetchJoinQuery = true)
{
return new DoctrinePaginator($query, $isFetchJoinQuery);
}
}