This is a small tutorial about How to make a pagination whit Zend Paginator
so we a have an action let say listAction
public function listAction() { $sql = ‘SELECT * FROM <strong style="color: black; background-color: #a0ffff;">table</strong>’; $result = $db->fetchAll($sql); $paginator = <strong style="color: black; background-color: #ffff66;">Zend_Paginator</strong>::factory($result); $paginator->setCurrentPageNumber($this->_getParam(’page’)); $paginator->setItemCountPerPage(10); //where 10 is the number of records per page $this->view->paginator = $paginator; $this->view->page_nr = $this->_getParam(’page’); $this->render(’list’); }
now let see the design list.phtml
<div> <<strong style="color: black; background-color: #a0ffff;">table</strong>> <tr> <td>Col1</td> <td>Col2</td> <td>Col3</td> <td>Col4</td> </tr> <?php foreach($this->paginator as $row): ?> <tr> <td><?= $this->escape($row['col1']) ?></td> <td><?= $this->escape($row['col2']) ?></td> <td><?= $this->escape($row['col3']) ?></td> <td><?= $this->escape($row['col4']) ?></td> </tr> <? endforeach ?> </<strong style="color: black; background-color: #a0ffff;">table</strong>> <?= $this->paginationControl($this->paginator2, ‘Sliding’, ‘p.phtml’);?> </div>
the code for p.phtml
<?php if ($this->pageCount): ?> <div class=”paginationControl”> <!– Previous page link –> <?php if (isset($this->previous)): ?> <a href=”<?= $this->url(array(’page’ => $this->previous)); ?>”> < Previous </a> | <?php else: ?> <span class=”disabled”>< Previous</span> | <?php endif; ?> <!– Numbered page links –> <?php foreach ($this->pagesInRange as $page): ?> <?php if ($page != $this->current): ?> <a href=”<?= $this->url(array(’page’ => $page)); ?>”> <?= $page; ?> </a> | <?php else: ?> <?= $page; ?> | <?php endif; ?> <?php endforeach; ?> <!– Next page link –> <?php if (isset($this->next)): ?> <a href=”<?= $this->url(array(’page’ => $this->next)); ?>”> Next > </a> <?php else: ?> <span class=”disabled”>Next ></span> <?php endif; ?> </div> <?php endif; ?>
p.phtml must be in the root of the template files, main is application/views/scripts/
more information you can find here