NewsFeaturesDownloadsDevelopmentSupportAbout Us

Pager

generic implementation of a pager. It doesn't take of generating SQL queries for paging or anythign like that, it only takes care of generating the number of pages based on the number of registers, keeping track of the current page, etc.

There also needs to be some display logic in order to get it to work fine.

At the PHP level, some code like this is necessary:

 $pager = new Pager( "?op=editPosts&showStatus={$this->_showStatus}&page=",
                     $this->_page, 
                     $numPosts, 
                     $this->_itemsPerPage );
 $view->setValue( "pager", $pager );
 

The first parameter passed to the constructor is the string that the pager class will use to generate the page links. It will only append a page number, nothing else.

At the Smarty/template level, some code like this is necessary in order to display the links properly, etc:

   {if !$pager->isFirstPage() && !$pager->isEmpty()}
      <a class="pagerLink" href="{$pager->getPrevPageLink()}">Prev</a> 
   {/if}	
   {foreach from=$pager->getPageLinks() item=pageLink key=pageId}
     {if $pageId == $pager->getCurrentPage()}
       <span class="pagerCurrent"> {$pageId} >/span<
     {else}
       <a class="pagerLink" href="{$pageLink}"> {$pageId} </a> 
     {/if}  
   {/foreach}
   {if !$pager->isLastPage() && !$pager->isEmpty()}
       <a class="pagerLink" href="{$pager->getNextPageLink()}">Next</a> 
   {/if}
 

The display logic might look a bit complex but it is unavoidable...