I have 6 records in query and this code correctly show it on 3 pages:
(action)
public function listAction()
{
$page = (int) $this->params()->fromRoute('id', 0);
$posts = $this->getPagesTable()->selectPages();
$paginator = new Paginator(new PaginatorIterator($posts));
$paginator->setCurrentPageNumber($page)
->setItemCountPerPage(2)
->setPageRange(7);
return new ViewModel(array(
'paginator' => $paginator,
));
}
(view)
<?php foreach ($paginator as $post) : ?>
<h2><?php echo $this->escapeHtml($post->id); ?></h2>
<div><?php echo $this->escapeHtml($post->name);?>
<?php endforeach; ?>
but when I add foreach loop in action:
public function listAction()
{
$page = (int) $this->params()->fromRoute('id', 0);
$posts = $this->getPagesTable()->selectPages();
$paginator = new Paginator(new PaginatorIterator($posts));
$paginator->setCurrentPageNumber($page)
->setItemCountPerPage(2)
->setPageRange(7);
foreach ($paginator as $post) {
// some code or empty foreach
};
return new ViewModel(array(
'paginator' => $paginator,
));
}
paginator don't show last (3) page (1 and 2 page show correctly). Why? Thank you!
If add $paginator->getIterator()->rewind() after foreach {}, paginator show only first page and don't show second and third pages.