I have 6 entries in the request, and this code correctly shows 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 the foreach loop to the 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) {
paginator does not show the last (3) page (correctly shown on page 1 and page 2). Why? Thanks!
If add $ paginator-> getIterator () β rewind () after foreach {}, paginator displays only the first page and does not display the second and third pages.
morin source share