Guest User

Untitled

a guest
Oct 17th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. (action)
  2. public function listAction()
  3. {
  4. $page = (int) $this->params()->fromRoute('id', 0);
  5. $posts = $this->getPagesTable()->selectPages();
  6. $paginator = new Paginator(new PaginatorIterator($posts));
  7. $paginator->setCurrentPageNumber($page)
  8. ->setItemCountPerPage(2)
  9. ->setPageRange(7);
  10. return new ViewModel(array(
  11. 'paginator' => $paginator,
  12. ));
  13. }
  14. (view)
  15. <?php foreach ($paginator as $post) : ?>
  16. <h2><?php echo $this->escapeHtml($post->id); ?></h2>
  17. <div><?php echo $this->escapeHtml($post->name);?>
  18. <?php endforeach; ?>
  19.  
  20. public function listAction()
  21. {
  22. $page = (int) $this->params()->fromRoute('id', 0);
  23. $posts = $this->getPagesTable()->selectPages();
  24. $paginator = new Paginator(new PaginatorIterator($posts));
  25. $paginator->setCurrentPageNumber($page)
  26. ->setItemCountPerPage(2)
  27. ->setPageRange(7);
  28. foreach ($paginator as $post) {
  29. // some code or empty foreach
  30. };
  31. return new ViewModel(array(
  32. 'paginator' => $paginator,
  33. ));
  34. }
  35.  
  36. i am using iterator_to_array($userList);
Add Comment
Please, Sign In to add comment