0
votes

I have written code in controller given below,

$iteratorAdapter  = new \Zend\Paginator\Adapter\Iterator($this->getCategoryTable()->listCategoryData());
$paginatorDatas = new \Zend\Paginator\Paginator($iteratorAdapter);
$paginatorDatas->setCurrentPageNumber($page)->setItemCountPerPage(5); 

and I render the variable $paginatorDatas to view file.

In the corresponding view file, I have written the code like this,

echo $this->paginationControl($this->paginatorDatas, 'Elastic', 'paginator.phtml');

Before calling $this->paginationControl() function I have iterated the array object($paginatorDatas), through foreach(){} to populate records.

But the above code gives the following error,

Fatal error: Uncaught exception 'Zend\Db\Adapter\Exception\RuntimeException' with message 'This result is a forward only result set, calling rewind() after moving forward is not supported' in /var/www/cp/vendor/zendframework/zendframework/library/Zend/Db/Adapter/Driver/Pdo/Result.php:153 Stack trace: #0 [internal function]: Zend\Db\Adapter\Driver\Pdo\Result->rewind() #1 /var/www/cp/module/Admin/view/admin/category/ajax-list.phtml(21): LimitIterator->rewind() #2 /var/www/cp/vendor/zendframework/zendframework/library/Zend/View/Renderer/PhpRenderer.php(507): include('/var/www/cp/mod...') #3 /var/www/cp/vendor/zendframework/zendframework/library/Zend/View/View.php(205): Zend\View\Renderer\PhpRenderer->render(Object(Zend\View\Model\ViewModel)) #4 /var/www/cp/vendor/zendframework/zendframework/library/Zend/Mvc/View/Http/DefaultRenderingStrategy.php(102): Zend\View\View->render(Object(Zend\View\Model\ViewModel)) #5 [internal function]: Zend\Mvc\View\Http\DefaultRenderingStrategy->render(Object(Zend\Mvc\MvcEvent)) #6 /var/www/cp/ in /var/www/cp/vendor/zendframework/zendframework/library/Zend/Db/Adapter/Driver/Pdo/Result.php on line 153

Please help me....

2

2 Answers

1
votes

Method 1

$resultSet = $this->getCategoryTable()->listCategoryData();
$resultSet->buffer();
$resultSet->next();
$iteratorAdapter  = new \Zend\Paginator\Adapter\Iterator($resultSet);
$paginatorDatas = new \Zend\Paginator\Paginator($iteratorAdapter);
$paginatorDatas->setCurrentPageNumber($page)->setItemCountPerPage(5);

From this tutorial from Samsonasik

Method 2

$resultSet = $this->getCategoryTable()->listCategoryData();
$resultSet = iterator_to_array($resultSet);
$adapter  = new \Zend\Paginator\Adapter\ArrayAdapter($resultSet);
$paginatorDatas = new \Zend\Paginator\Paginator($adapter);
$paginatorDatas->setCurrentPageNumber($page)->setItemCountPerPage(5);
0
votes

Populate an array with your query result and you can use an \Zend\Paginator\Adapter\ArrayAdapter instead of \Zend\Paginator\Adapter\Iterator