yamcsha

Zend - Paginator (DbAdapter)

May 7th, 2012
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.76 KB | None | 0 0
  1. <?php
  2. $db     = Zend_Db_Table::getDefaultAdapter();
  3. $select = $db->select()->from(array('t'=> 'table_name'));
  4.  
  5. $paginator = new Zend_Paginator(new Zend_Paginator_Adapter_DbSelect($select));
  6. $paginator->setItemCountPerPage(20)
  7.           ->setCurrentPageNumber($this->_getParam('page', 1))
  8.           ->setPageRange(10);
  9.        
  10. $this->view->paginator = $paginator;
  11. ?>
  12.  
  13. // Controller View
  14. <?php foreach($this->paginator as $item): ?>
  15. <?= $this->paginationControl($this->paginator, 'Sliding', 'partials/paginator.phtml'); ?>
  16.  
  17. // paginator view helper
  18. <?php
  19. if ($this->pageCount > 1)
  20.     $this->previous
  21.     foreach ($this->pagesInRange as $page) {
  22.     if ($page != $this->current)
  23.             echo 'link';
  24.         else
  25.             echo 'text';
  26.     }
  27.     $this->next
  28. }
Advertisement
Add Comment
Please, Sign In to add comment