Login   Register  
PHP Classes
elePHPant
Icontem

File: example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of djomla  >  Paginate simple  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: example - howto - usage
Class: Paginate simple
Generate links for paginating listings
Author: By
Last change:
Date: 2011-02-23 01:23
Size: 1,868 bytes
 

Contents

Class file image Download
<?php
include ("Paginate.php");

$pagination = new Paginate (array(
                            
'numItems' =>  10// number of results
                            
'perPage' => 2// items you want to display per page
                            
'url' => '/list_my_results.php?page=' // url for pagination
                        
));
$paginater $pagination->dispatch();

# And now methods ##
$pagination->hasPrevPage(); // returns boolean
$pagination->getPrevPage()->getLink();
$pagination->getPrevPage()->getNumber();
$pagination->getFirstPage()->getLink();
$pagination->getLastPage();

$pagination->getDisplayPages(); // returns array of PaginatePage objects
$pagination->getCurrentPage(); //

## Now i will display smarty template i use for pagination ##


<div id="pagination">
    {if 
$pagination->hasPrevPage()}
        <
a href="{$pagination->getPrevPage()->getLink()}title="« Previous">« Previous</a>
    {else}
        <
span class="disabled">« Previous</span>
    {/if}

    {if 
$pagination->getCurrentPage-1}
        <
a href="{$pagination->getFirstPage()->getLink()}title="{$pagination->getFirstPage()->getNumber()}">{$pagination->getFirstPage()->getNumber()}</a>
    {/if}

    {foreach 
from=$pagination->getDisplayPages() item=dpage}
        {if 
$pagination->getCurrentPage() == $dpage->getNumber()}
            <
span class="active">{$dpage->getNumber()}</span>
        {else}
            <
a href="{$dpage->getLink()}title="{$dpage->getNumber()}">{$dpage->getNumber()}</a>
        {/if}
    {/foreach}

    {if 
$pagination->getCurrentPage()+$pagination->getTotalPages()}
        <
a href="{$pagination->getLastPage()->getLink()}title="{$pagination->getLastPage()->getNumber()}">{$pagination->getLastPage()->getNumber()}</a>
    {/if}

    {if 
$pagination->hasNextPage() AND $pagination->getTotalPages() > $pagination->getCurrentPage()+3}
        <
a href="{$pagination->getNextPage()->getLink()}title="Next »">Next »</a>
    {else}
        <
span class="disabled">Next »</span>
    {/if}
</
div>

?>