ZF2 settings are not displayed on the last page

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) { // some code or empty foreach }; return new ViewModel(array( 'paginator' => $paginator, )); } 

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.

+6
source share
2 answers

The iterator pattern looks like a pointer, and you try resetting it again.

0
source

I also faced the same problem

But now I decided

 i am using iterator_to_array($userList); 

on the browse page after deleting this line it works fine maybe this will help you

0
source

All Articles