我在下面给出了控制器中的代码,
$iteratorAdapter = new \Zend\Paginator\Adapter\Iterator($this->getCategoryTable()->listCategoryData());
$paginatorDatas = new \Zend\Paginator\Paginator($iteratorAdapter);
$paginatorDatas->setCurrentPageNumber($page)->setItemCountPerPage(5);
我将变量 $ paginatorDatas 呈现给查看文件。
在相应的视图文件中,我编写了这样的代码,
echo $this->paginationControl($this->paginatorDatas, 'Elastic', 'paginator.phtml');
在调用$ this-> paginationControl()函数之前,我已经迭代了数组对象( $ paginatorDatas ),通过foreach(){}
来填充记录。
但上面的代码给出了以下错误,
致命错误:未捕获异常'Zend \ Db \ Adapter \ Exception \ RuntimeException',带有消息'此结果是仅向前结果集,在/ var / www / cp /中不支持向前移动后调用rewind() vendor / zendframework / zendframework / library / Zend / Db / Adapter / Driver / Pdo / Result.php:153堆栈跟踪:#0 [内部函数]: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(对象(Zend \ View \ Model \ ViewModel))#4 / var / www / cp / vendor / zendframework / zendframework / library / Zend /Mvc/View/Http/DefaultRenderingStrategy.php(102):Zend \ View \ View-> render(对象(Zend \ View \ Model \ ViewModel))#5 [内部函数]:Zend \ Mvc \ View \ Http \ DefaultRenderingStrateg y-> render(Object(Zend \ Mvc \ MvcEvent))#6 / var / www / cp / in / var / www / cp / vendor / zendframework / zendframework / library / Zend / Db / Adapter / Driver / Pdo /第153行的Result.php
请帮助我....
答案 0 :(得分:1)
方法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);
来自Samsonasik的this教程
方法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);
答案 1 :(得分:0)
使用您的查询结果填充数组,您可以使用\Zend\Paginator\Adapter\ArrayAdapter
代替\Zend\Paginator\Adapter\Iterator