ThinkPHP分页实例
(2014-09-20 15:34:36)很多人初学thinkphp时,不太熟悉thinkphp的分页使用方法,现在将自己整理的分页方法分享下,有需要的朋友可以看看。
控制器中的代码:
$where = "查询条件";
$count = $db->where($where)->count();
$pagecount = 20;
$page = new ThinkPage($count , $pagecount);
$page->parameter = $row; //此处的row是数组,为了传递查询条件
$page->setConfig('first','首页');
$page->setConfig('prev','上一页');
$page->setConfig('next','下一页');
$page->setConfig('last','尾页');
$page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% 第 '.I('p',1).' 页/共 %TOTAL_PAGE% 页 ( '.$pagecount.' 条/页 共 %TOTAL_ROW% 条)');
$show = $page->show();
$list = $db->where($where)->order('id desc')->limit($page->firstRow.','.$page->listRows)->select();
$this->assign('list',$list);
$this->assign('page',$show);
$this->display();
模版中调用代码:
<**div class="pagelist">{$page}<**/div**>
//博客中会过滤DIV标签,请将上面一句话中的**去除,再使用
附带分页样式:
.pagelist{ text-align:center; background:#f1f1f1; padding:7px 0;}
.pagelist a{ margin:0 5px; border:#6185a2 solid 1px; display:inline-block; padding:2px 6px 1px; line-height:16px; background:#fff; color:#6185a2;}
.pagelist span{ margin:0 5px; border:#6185a2 solid 1px; display:inline-block; padding:2px 6px 1px; line-height:16px; color:#6185a2; color:#fff; background:#6185a2;}
显示效果如下: