控制器中的代码:
$db = M("cost");
$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>
附带分页样式:
.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;}