PEAR探奇之PEAR::Pager
2005-09-29
Haohappy
<http://blog.csdn.net/haohappy2004>
在页面上显示大量数据,是WEB项目中很常见的一个作法,但限于屏幕的大小,为了便于用户阅读,我们通常需要将数据分页显示,所以分页功能是大部份项目不可缺少的。PEAR::Pager是一个功能强大的分页类,使用非常方便。
系统需求:
PHP4.3.*
/PHP5
PEAR::Pager
PEAR::Pager有两种分页显示模式,一是Jumping,二是Sliding。两者有什么区别,我们来看两个例子:
Jumping.php
<?php
require_once 'Pager/Pager.php';
$params = array(
'mode' => 'Jumping',
'perPage' => 3,
'delta' => 5,
'itemData' => array('a','b','c','d','e','z','ty','xc','fg','fg','jk','hj','ty','xc','e','z','ty','xc','fg','fg','jk','hj','ty','xc')
);
echo "<BR>当前分页模式:".$params['mode'];
echo "<BR>每页显示数据条数:".$params['perPage'];
echo "<BR>显示页数:".$params['delta'];
echo "<BR>详细数据数组:";
print_r($params['itemData']);
$pager = & Pager::factory($params);
$data = $pager->getPageData();
$links = $pager->getLinks();
echo "<P>最后效果:";
echo $links['all'];
echo $pager->linkTags;
echo '<P>当前页的数据: ' ;
echo "<pre>";
print_r($data);
echo "</pre>";
echo "其它类方法得到的数据:<P>";
echo 'getCurrentPageID()...: ';
var_dump($pager->getCurrentPageID());
echo "<BR>";
echo 'getNextPageID()......: ';
var_dump($pager->getNextPageID());
echo "<BR>";
echo 'getPreviousPageID()..: ';
var_dump($pager->getPreviousPageID());
echo "<BR>";
echo 'numItems()...........: ';
var_dump($pager->numItems());
echo "<BR>";
echo 'numPages()...........: ';
var_dump($pager->numPages());
echo "<BR>";
echo 'isFirstPage()........: ';
var_dump($pager->isFirstPage());
echo "<BR>";
echo 'isLastPage().........: ';
var_dump($pager->isLastPage());
echo "<BR>";
echo 'isLastPageComplete().: ';
var_dump($pager->isLastPageComplete());
echo "<BR>";
echo '$pager->range........: ';
var_dump($pager->range); echo "<BR>";
?>
运行结果如下图: