這篇文章給大家分享的是有關(guān)thinkphp3.2.3怎么實(shí)現(xiàn)分頁的內(nèi)容。小編覺得挺實(shí)用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。

對于thinkphp分頁的實(shí)現(xiàn)效果,兩種調(diào)用方法,一種調(diào)用公共函數(shù)中的函數(shù)方法,一種是在模型中書寫分頁的方法

1、在公共函數(shù)Application/Common/Common/function.php中書寫:
function getpage($count,$pagesize=10) {
$page=new Think\Page($count,$pagesize);
$page->setConfig('header', '<li>共<b>%TOTAL_ROW%</b>條記錄 <b>%NOW_PAGE%</b>/<b>%TOTAL_PAGE%</b>頁</li>');
$page->setConfig('prev', '上一頁');
$page->setConfig('next', '下一頁');
$page->setConfig('last', '末頁');
$page->setConfig('first', '首頁');
$page->setConfig('theme', '%FIRST%%UP_PAGE%%LINK_PAGE%%DOWN_PAGE%%END%%HEADER%');
$page->lastSuffix=false;//最后一頁不顯示總頁數(shù)
return $page;
}在控制器PageController.class.php中調(diào)用
namespace Home\Controller;
use Think\Controller;
class PageController extends Controller {
public function index() {
$m=M('user');
$count=$m->count();
$page= getpage($count,8);//Common/function.php中分頁
$list=$m->limit($page->firstRow,$page->listRows)->select();
$this->assign('list',$list);//賦值數(shù)據(jù)集
$this->assign('page',$page->show());//賦值分頁輸出
$this->display();
}
}在視圖index/index.html中顯示
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="__CSS__/page.css" rel="stylesheet" />
</head>
<body>
<div>
<volist name="list" id="vo">
<notemply name="$vo['name']">
用戶名:<p>{$vo['name']}</p>
</notemply>
</volist>
<div>
<table>
<tr>
<td colspan="3" bgcolor="#FFFFFF">
<div class="pages">{$page} </div>
</td>
</tr>
</table>
</div>
</div>
</body>
</html>樣式的書寫page.css
.pages a,.pages span {
display:inline-block;
padding:2px 5px;
margin:0 1px;
border:1px solid #f0f0f0;
-webkit-border-radius:3px;
-moz-border-radius:3px;
border-radius:3px;
}
.pages a,.pages li {
display:inline-block;
list-style: none;
text-decoration:none; color:#58A0D3;
}
.pages a.first,.pages a.prev,.pages a.next,.pages a.end{
margin:0;
}
.pages a:hover{
border-color:#50A8E6;
}
.pages span.current{
background:#50A8E6;
color:#FFF;
font-weight:700;
border-color:#50A8E6;
}2、在模板UserModel.class.php中書寫分頁函數(shù)
namespace Home\Model;
use Think\Model;
class UserModel extends Model {
public function getPage() {
$page=I('p',0,'int');
$limit=8;
$data=$this->page($page,$limit)->select();
$count= $this->count();
$Page=new \Think\Page($count, $limit);
$Page->lastSuffix=false;//是否顯示總頁數(shù)
$Page->setConfig('header','<li>共<b>%TOTAL_ROW%</b>幅圖片 每頁<b>'.$limit.'</b>幅 <b>%NOW_PAGE%</b>/<b>%TOTAL_PAGE%</b>頁</li>');
$Page->setConfig('prev','上一頁');
$Page->setConfig('next','下一頁');
$Page->setConfig('last','末頁');
$Page->setConfig('first','首頁');
$Page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');
$show=$Page->show();
return array('list'=>$data,'page'=>$show);
}
}控制器PageController.class.php中調(diào)用
namespace Home\Controller;
use Think\Controller;
class PageController extends Controller {
public function index() {
$m=D('Upload_img');
$list=$m->getPage();//model中分頁
$this->assign('list',$list);//賦值數(shù)據(jù)集
$this->display();
}
}視圖顯示index/index.html
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="__CSS__/page.css" rel="stylesheet" />
</head>
<body>
<div>
<volist name="list.list" id="vo">
<notemply name="$vo['name']">
用戶名:<p>{$vo['name']}
</notemply>
</volist>
<div>
<table>
<tr>
<td colspan="3" bgcolor="#FFFFFF">
<div class="pages">{$list.page} </div>
</td>
</tr>
</table>
</div>
</div>
</body>
</html>分頁的樣式與第1中公共方法中page.css中樣式相同
以上<link href="__CSS__/page.css" rel="stylesheet" />引用文件常量"__CSS__"在公共配置文件中配置:
return array( 'TMPL_PARSE_STRING'=>array( '__CSS__'=>__ROOT__.'/Public/Css', ))
感謝各位的閱讀!關(guān)于“thinkphp3.2.3怎么實(shí)現(xiàn)分頁”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,讓大家可以學(xué)到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!
本文標(biāo)題:thinkphp3.2.3怎么實(shí)現(xiàn)分頁-創(chuàng)新互聯(lián)
分享地址:http://www.chinadenli.net/article14/deicde.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App設(shè)計、網(wǎng)站收錄、品牌網(wǎng)站制作、網(wǎng)站改版、App開發(fā)、虛擬主機(jī)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容