Zend_Paginator / Doctrine 2

I use Doctrine 2 with my Zend Framework application, and a typical query result can yield a million (or more) search results.

I want to use Zend_Paginator according to this result set. However, I do not want to return all the results as an array and use the Array adapter, since this would be inefficient, instead I would like to provide paginator with the total number of rows, and then an array of results based on the sums of limit / offset values.

Can this be done using an Array adapter or do I need to create my own pagination adapter?

+3
source share
3 answers

. Array , - . , DQL statemenet /.

+3

Zend_Paginator_Adapter_Interface, Zend_Paginator_Adapter_Iterator.

Doctrine Paginator Zend_Paginator_Adapter_Iterator :

use Doctrine\ORM\Tools\Pagination as Paginator; // goes at top of file

SomeController::someAction() 
{
 $dql = "SELECT s, c FROM Square\Entity\StampItem s JOIN s.country c ".' ORDER BY '.  $orderBy . ' ' . $dir;

 $query = $this->getEntityManager()->createQuery($dql);
 $d2_paginator = new Paginator($query); 

 $d2_paginator_iter = $d2_paginator->getIterator(); // returns \ArrayIterator object

 $adapter =  new \Zend_Paginator_Adapter_Iterator($d2_paginator_iter);

 $zend_paginator = new \Zend_Paginator($adapter);          

 $zend_paginator->setItemCountPerPage($perPage)
            ->setCurrentPageNumber($current_page);

 $this->view->paginator = $zend_paginator; 
}

paginator script , .

:

Zend_Paginator Zend_Paginator_Adapter_Interface, Zend_Paginator_Adpater_Iterator. Zend_Paginator_Adapter_Iterator \. \ \ ( , Zend_Paginator_Adapter_Iterator). Paginator:: getIterator() \ArrayIterator, ( \ArrayIterator \Iterator \).

See this port from Doctrine 1 to Docrine 2 code for the β€œZend Framework: Beginner's Guide” from Doctrine 1 to Doctrine: https://github.com/kkruecke/zf-beginners-doctrine2 . It includes pagination code using Zend_Paginator using Zend_Paginator_Adapter_Iterator with Doctrine 2 ' Doctrine \ ORM \ Tools \ Pagination \ Paginator .

0
source

Source: https://habr.com/ru/post/1795761/


All Articles