01-17-2008, 06:04 PM
|
#5 (permalink)
|
|
The Frequenter
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
|
Quote:
Originally Posted by Wildhoney
|
If it helps, there is a proposel for Zend_Paginator in the works - doesn't look like it's going anywhere fast though :(
You are right though, pagination really is a custom job depending on the application layout, data source, etc.
Edit: And if you did need a pagination class for the Zend Framework, here's a view script that Matthew posted to the mailing list ages ago that should still work pretty well:
PHP Code:
<?php
$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"><<</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">>></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.
*/
Alan
|
|
|