Thank you Matthew !!!

2007/2/14, Matthew Weier O'Phinney <[EMAIL PROTECTED]>:

-- Adler Medrado <[EMAIL PROTECTED]> wrote
(on Wednesday, 14 February 2007, 05:17 PM -0200):
> Does anyone here have a sample code of pagination with the Zend
Framework?

Here's a view script I include on pages needing a pager:

    $pages = $this->pages;
    $count = count($pages);
    if (1 < $count):
        $startPage = 1;
        $endPage   = $count;

        if ($count > 9) {
            $startPage = ($this->curPage < 6) ? 1 : $this->curPage - 4;
            $endPage   = ($this->curPage + 4 > $count) ? $count :
$this->curPage + 4;
            if (($startPage < 5) && ($endPage < $count)) {
                $endPage = $startPage + 8;
            } elseif (($endPage == $count) && ($endPage - $startPage < 9))
{
                $startPage = $endPage -8;
            }
        }
    ?>
    <ul class="pager">
        <? if (1 < $this->curPage): ?><li><a href="<?= $baseUrl ?>1"
title="first page">&lt;&lt;</a></li><? endif ?>
        <? if ($this->curPage > 1):?><li><a href="<?= $baseUrl ?><?=
$this->curPage - 1 ?>" title="previous page">prev</a></li><? endif; ?>
    <? for ($i = $startPage; $i <= $endPage; $i++): ?>
        <? $page = $i ?>
        <? if ($this->curPage == $page): ?>
        <li class="current"><?= $page ?></li>
        <? else: ?>
        <li><a href="<?= $baseUrl ?><?= $page ?>" title="page <?= $page
?>"><?= $page ?></a></li>
        <? endif; ?>
    <? endfor ?>
        <? if ($this->curPage < $count):?><li><a href="<?= $baseUrl ?><?=
$this->curPage + 1 ?>" title="next page">next</a></li><? endif; ?>
        <? if ($count > $this->curPage): ?><li><a href="<?= $baseUrl ?><?=
$count ?>" title="last page">&gt;&gt;</a></li><? endif ?>
    </ul>
    <? endif ?>

Usage is that you set the following:

    $view->baseUrl = $baseUrlToData;
    $view->pages   = $numPages;
    $view->curPage = $currentPage;

It creates a sliding pager -- i.e., it doesn't show *all* pages, but a
window
of 8 pages, with links to the prev/next pages and first/last pages.

It's up to your controller, then, to determine (a) how many items to
display per page, and thus (b) how many pages there are, as well as (c)
the routing schema you'll use for getting to different pages (hence the
baseUrl). You determine the current page based on the page requested.

--
Matthew Weier O'Phinney
PHP Developer            | [EMAIL PROTECTED]
Zend - The PHP Company   | http://www.zend.com/




--
adler medrado

Nesher Technologies
Brasília, DF, Brasil.
http://www.neshertech.net
http://adler.neshertech.net

Reply via email to