View Single Post
Old 01-17-2008, 06:04 PM   #5 (permalink)
Alan @ CIT
Member of the Month
The Frequenter
Member of the Month Top Contributor 
 
Alan @ CIT's Avatar
 
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
Alan @ CIT is on a distinguished road
Default

Quote:
Originally Posted by Wildhoney View Post
but when a search for a pagination class in Zend's own Zend Framework yields very few results
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 (
$count):
       
$startPage 1;
       
$endPage   $count;

       if (
$count 9) {
           
$startPage = ($this->curPage 6) ? $this->curPage 4;
           
$endPage   = ($this->curPage $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 ($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.
*/
Alan
Send a message via MSN to Alan @ CIT
Alan @ CIT is offline  
Reply With Quote