i want to use doctrine with zend_paginator
here some example query :
$allArticleObj =
$this->_em->getRepository(‘Articles’);
$qb = $this->_em->createQueryBuilder();$qb->add('select', 'a') ->add('from', 'Articles a') ->setFirstResult(0) ->setMaxResults(5);
is there any example code to show we can write a zend_paginator adapter for doctrine 2 query builder?
The upshot, of course, is that you have to implement the
Zend_Paginator_Adapter_Interface, which essentially means implementing the two methods:count()getItems($offset, $perPage)Your adapter would accept the Doctrine query as a constructor argument.
In principle, the
getItems()part is actually straightforward. Simply, add the$offsetand$perPagerestrictions to the query – as you are doing in your sample – and execute the query.In practice, it’s the
count()business that tends to be tricky. I’d follow the example ofZend_Paginator_Adapter_DbSelect, replacing theZend_Dboperations with theirDoctrineanalogues.