Lapozás megoldva:
Tesztelve: Frog 0.9.5 RC2 alatt!
base_url - a lapozni kívánt oldal megnevezése
per_page - bejegyzések megjelenése oldalanként
num_links - hány oldal jelenlen meg
Ezt a kódrészt abba az oldalba helyezd el amit lapozni szeretnél:
<?php use_helper('Pagination');
$pagination = new Pagination(array(
'base_url' => 'oldalcim',
'total_rows' => $this->childrenCount(),
'per_page' => 10,
'num_links' => 8,
'cur_page' => (isset($_GET['page']) ? $_GET['page']: 1)
));
if ($pagination->total_rows > $pagination->per_page)
echo '<p><br />Oldalak: '.$pagination->createLinks().'</p>';
?>
Ezt a kódot ments el egy Pagination.php fájba és másold be a frog - helpers mappába. Amennyiben a Frog 0.9.5 RC2-t használod, az ott megtalálható (frog-helpers-pagination.php -t) írd felül ezzel.
<?php
/**
* Pagination class
*
* @version 0.1
* @package Frog
* @author Modif: Philippe Archambault <philippe.archambault@gmail.com>
* @author CodeIgniter helper
*/
class Pagination
{
var $base_url = ''; // The page we are linking to
var $total_rows = ''; // Total number of items (database results)
var $per_page = 10; // Max number of items you want shown per page
var $num_links = 3; // Number of "digit" links to show before/after the currently viewed page
var $cur_page = 1; // The current page being viewed
var $first_link = '‹ Első';
var $next_link = '>';
var $prev_link = '<';
var $last_link = 'Utolsó ›';
var $full_tag_open = '';
var $full_tag_close = '';
var $first_tag_open = '';
var $first_tag_close = ' ';
var $last_tag_open = ' ';
var $last_tag_close = '';
var $cur_tag_open = ' <b>';
var $cur_tag_close = '</b>';
var $next_tag_open = ' ';
var $next_tag_close = ' ';
var $prev_tag_open = ' ';
var $prev_tag_close = '';
var $num_tag_open = ' ';
var $num_tag_close = '';
/**
* Constructor
*
* @param array initialization parameters
*/
function __construct($params = array())
{
if (count($params) > 0)
$this->initialize($params);
}
/**
* Initialize Preferences
*
* @param array initialization parameters
* @return void
*/
function initialize($params = array())
{
if (count($params) > 0)
foreach ($params as $key => $val)
if (isset($this->$key))
$this->$key = $val;
} // initialize
/**
* Generate the pagination links
*
* @return string
*/
function createLinks()
{
// If our item count or per-page total is zero there is no need to continue.
if ($this->total_rows == 0 || $this->per_page == 0)
return '';
// Calculate the total number of pages
$num_pages = ceil($this->total_rows / $this->per_page);
// Is there only one page? Hm... nothing more to do here then.
if ($num_pages == 1)
return '';
// Calculate the start and end numbers. These determine
// which number to start and end the digit links with
$start = (($this->cur_page - $this->num_links) > 0) ? $this->cur_page - ($this->num_links - 1) : 1;
$end = (($this->cur_page + $this->num_links) < $num_pages) ? $this->cur_page + $this->num_links : $num_pages;
// And here we go...
$output = '';
// Render the "First" link
if ($this->cur_page > $this->num_links)
$output .= $this->first_tag_open.'<a href="'.$this->base_url.'">'.$this->first_link.'</a>'.$this->first_tag_close;
// Write the digit links
for ($page = $start -1; $page <= $end; $page++)
if ($page > 0)
if ($this->cur_page == $page)
$output .= $this->cur_tag_open.$page.$this->cur_tag_close; // Current page
else
$output .= $this->num_tag_open.'<a href="'.$this->base_url.'&page='.$page.'">'.$page.'</a>'.$this->num_tag_close;
// Render the "Last" link
if (($this->cur_page + $this->num_links) < $num_pages)
$output .= $this->last_tag_open.'<a href="'.$this->base_url.'&page='.$num_pages.'">'.$this->last_link.'</a>'.$this->last_tag_close;
// Kill double slashes. Note: Sometimes we can end up with a double slash
// in the penultimate link so we'll kill all double shashes.
$output = preg_replace("#([^:])//+#", "\\1/", $output);
// Add the wrapper HTML if exists
$output = $this->full_tag_open.$output.$this->full_tag_close;
return $output;
}
} // Pagination
Sok szerencsét a használatához.