Zend_Paginator Full Example

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)); ?>”>
&lt; Previous
</a> |
<?php else: ?>
<span class=”disabled”>&lt; 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 &gt;
</a>
<?php else: ?>
<span class=”disabled”>Next &gt;</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

affiliate_link
Share this Post:
Digg Google Bookmarks reddit Mixx StumbleUpon Technorati Yahoo! Buzz DesignFloat Delicious BlinkList Furl

No Responses to “Zend_Paginator Full Example”

Leave a Reply:

Name (required):
Mail (will not be published) (required):
Website:
Comment (required):
XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>