http://www.cnblogs.com/tdalcn/archive/2011/04/23/2025592.html
Pager 分页函数
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- function FLEA_Helper_Pager(& $source, $currentPage, $pageSize = 20, $conditions = null, $sortby = null, $basePageIndex = 0)
- {
- $this->_basePageIndex = $basePageIndex;
- $this->_currentPage = $this->currentPage = $currentPage;
- $this->pageSize = $pageSize;
-
- if (is_object($source)) {
- $this->source =& $source;
- $this->_conditions = $conditions;
- $this->_sortby = $sortby;
- $this->totalCount = $this->count = (int)$this->source->findCount($conditions);
- $this->computingPage();
- } elseif (!emptyempty($source)) {
- $this->source = $source;
- $sql = "SELECT COUNT(*) FROM ( $source ) as _count_table";
- $this->dbo =& FLEA::getDBO();
- $this->totalCount = $this->count = (int)$this->dbo->getOne($sql);
- $this->computingPage();
- }
- }
Pager 参数说明
$source 数据库操作类
$currentPage 当前页
$pageSize 每页显示记录数量
$conditions 查询条件
$sortby 排序方式
$basePageIndex 页码基数
实例:
- $dirname = dirname(__FILE__);
- define('APP_DIR', $dirname . '/APP');
- define('NO_LEGACY_FLEAPHP', true);
- require($dirname.'/FleaPHP/FLEA/FLEA.php');
-
-
- FLEA::setAppInf('internalCacheDir',$dirname.'/_Cache');
-
-
-
- $dsn = array(
- 'driver' => 'mysql',
- 'host' => 'localhost',
- 'login' => 'root',
- 'password' => '',
- 'database' => 'wordpress'
- );
-
- FLEA::setAppInf('dbDSN',$dsn);
-
-
- FLEA::loadClass('FLEA_Db_TableDataGateway');
- FLEA::loadClass('FLEA_Helper_Pager');
- $page_size='10'; //每页记录数
$page = (isset($_GET['page']))?(int)$_GET['page']:1;
$conditions = array(
'ss_state'=>0,
);
$pager = new FLEA_Helper_Pager($this->_shuoshuo,$page,$page_size,$conditions,'created DESC',1);
$rows =$pager->findAll();
$pager->setBasePageIndex(1); // 起始页码设为1
$this->smarty->assign('rowset',$rows);
$this->smarty->assign('newsNavbar', $pager->getNavbarIndexs($page, 8));
$this->smarty->assign('newsPager', $pager->getPagerData());
$url = array('ctl'=>'default','act'=>'helpinfo&act=shuoshuo');
$this->smarty->assign('url',$url);
<a href="{{url controller=$url.ctl action=$url.act page=$newsPager.firstPageNumber}}" title='首页'><<</a>{{section name=page loop=$newsNavbar}}{{if $newsNavbar[page].index == $newsPager.currentPage}}<b><font color='red'>[{{$newsNavbar[page].number}}]</font></b>{{else}}<a href="{{url controller=$url.ctl action=$url.act page=$newsNavbar[page].index}}">{{$newsNavbar[page].number}}</a>{{/if}}{{/section}}<a href="{{url controller=$url.ctl action=$url.act page=$newsPager.lastPageNumber}}" title='末页'>>></a><!-- 共有 <font color="Red">{{$newsPager.count}}</font> 条记录,分为 <font color="Red">{{$newsPager.pageCount}}</font> 页显示,每页 <font color="Red">{{$newsPager.pageSize}}</font> 条-->