




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
第tp5框架內(nèi)使用tp3.2分頁的方法分析本文實(shí)例講述了tp5框架內(nèi)使用tp3.2分頁的方法。分享給大家供大家參考,具體如下:
tp5內(nèi)使用tp3.2分頁
由于百度上面太多坑,所以自己拿來去改了一下
下面是完全可行的操作
首先吧tp3.2的分頁復(fù)制出來,拿到tp5extend文件夾下面的org里面,把tp3.2的分頁名稱改為Page.php
然后改一下里面的代碼
下面是改過后的代碼
namespaceorg;//命名規(guī)范
classPage{
public$firstRow;//起始行數(shù)
public$listRows;//列表每頁顯示行數(shù)
public$parameter;//分頁跳轉(zhuǎn)時(shí)要帶的參數(shù)
public$totalRows;//總行數(shù)
public$totalPages;//分頁總頁面數(shù)
public$rollPage=7;//分頁欄每頁顯示的頁數(shù)
public$lastSuffix=false;//最后一頁是否顯示總頁數(shù)
private$p='p';//分頁參數(shù)名
private$url='';//當(dāng)前鏈接URL
private$nowPage=1;
//分頁顯示定制
private$config=array(
'header'='span共%TOTAL_ROW%條記錄/span',
'prev'='',
'next'='',
'first'='1...',
'last'='...%TOTAL_PAGE%',
'theme'='%FIRST%%UP_PAGE%%LINK_PAGE%%DOWN_PAGE%%END%',
*架構(gòu)函數(shù)
*@paramarray$totalRows總的記錄數(shù)
*@paramarray$listRows每頁顯示記錄數(shù)
*@paramarray$parameter分頁跳轉(zhuǎn)的參數(shù)
publicfunction__construct($totalRows,$listRows=20,$parameter=array()){
config('var_page')$this-p=config('var_page');//設(shè)置分頁參數(shù)名稱
/*基礎(chǔ)設(shè)置*/
$this-totalRows=$totalRows;//設(shè)置總記錄數(shù)
$this-listRows=$listRows;//設(shè)置每頁顯示行數(shù)
$this-parameter=empty($parameter)input('param.'):$parameter;//因?yàn)閠p5無法直接獲取到$_GET,所以這里直接拿tp5的函數(shù)input('param.'),下面的一樣
$this-nowPage=empty(input('param.p'))1:intval(input('param.p'));
$this-nowPage=$this-nowPage0$this-nowPage:1;
$this-firstRow=$this-listRows*($this-now1);
*定制分頁鏈接設(shè)置
*@paramstring$name設(shè)置名稱
*@paramstring$value設(shè)置值
publicfunctionsetConfig($name,$value){
if(isset($this-config[$name])){
$this-config[$name]=$value;
*生成鏈接URL
*@paraminteger$page頁碼
*@returnstring
privatefunctionurl($page){
$ispage=str_replace(urlencode('[PAGE]'),$page,$this-url);
return$ispage;
*組裝分頁鏈接
*@returnstring
publicfunctionshow(){
if(0==$this-totalRows)return'';
/*生成URL*/
$this-parameter[$this-p]='[PAGE]';
$this-url=url(request()-action(),$this-parameter);//生成url改成tp5獲取當(dāng)前action的
/*計(jì)算分頁信息*/
$this-totalPages=ceil($this-totalRows/$this-listRows);//總頁數(shù)
if(!empty($this-totalPages)$this-nowPage$this-totalPages){
$this-nowPage=$this-totalPages;
/*計(jì)算分頁臨時(shí)變量*/
$now_cool_page=$this-rollPage/2;
$now_cool_page_ceil=ceil($now_cool_page);
$this-lastSuffix$this-config['last']=$this-totalPages;
//上一頁
$up_row=$this-now1;
$up_page=$up_row0'ahref="'.$this-url($up_row).'"rel="externalnofollow"'.$this-config['prev'].'/a':'';
//下一頁
$down_row=$this-nowPage+1;
$down_page=($down_row=$this-totalPages)'ahref="'.$this-url($down_row).'"rel="externalnofollow"'.$this-config['next'].'/a':'';
//第一頁
$the_first='';
if($this-totalPages$this-rollPage($this-now$now_cool_page)=1){
$the_first='ahref="'.$this-url(1).'"rel="externalnofollow"'.$this-config['first'].'/a
//最后一頁
$the_end='';
if($this-totalPages$this-rollPage($this-nowPage+$now_cool_page)$this-totalPages){
$the_end='ahref="'.$this-url($this-totalPages).'"rel="externalnofollow"'.$this-config['last'].'/a
//數(shù)字連接
$link_page="";
for($i=1;$i=$this-rollPage;$i++){
if(($this-now$now_cool_page)=0){
$page=$i;
}elseif(($this-nowPage+$now_cool_1)=$this-totalPages){
$page=$this-totalPages-$this-rollPage+$i;
}else{
$page=$this-now$now_cool_page_ceil+$i;
if($page0$page!=$this-nowPage){
if($page=$this-totalPages){
$link_page.='ahref="'.$this-url($page).'"rel="externalnofollow"'.$page.'/a
}else{
break;
}else{
if($page0$this-totalPages!=1){
$link_page.='span'.$page.'/span
//替換分頁內(nèi)容
$page_str=str_replace(
array('%HEADER%','%NOW_PAGE%','%UP_PAGE%','%DOWN_PAGE%','%FIRST%','%LINK_PAGE%','%END%','%TOTAL_ROW%','%TOTAL_PAGE%'),
array($this-config['header'],$this-nowPage,$up_page,$down_page,$the_first,$link_page,$the_end,$this-totalRows,$this-totalPages),
$this-config['theme']);
return"div{$page_str}/div
接著是獲取數(shù)據(jù)的代碼
首先要use
然后就可以直接根據(jù)tp3那樣寫了
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 政治意識(shí)形態(tài)的演變?cè)囶}及答案
- 機(jī)電工程2025年技術(shù)管理試題及答案
- 站務(wù)員復(fù)習(xí)試題附答案
- 公共政策的協(xié)調(diào)與合作試題及答案
- 譯林版八年級(jí)試卷及答案
- 西方國家的科學(xué)技術(shù)政策研究試題及答案
- 軟件測(cè)試工程師職業(yè)需求試題及答案分享
- 數(shù)據(jù)共享在公共政策中的重要性試題及答案
- 信息系統(tǒng)項(xiàng)目管理師考試常見問題與解答集合試題及答案
- 信息系統(tǒng)項(xiàng)目管理師考試重要細(xì)節(jié)總結(jié)試題及答案
- 2025年山東省濟(jì)南市歷下區(qū)中考一模地理試題(含答案)
- 建筑工程企業(yè)財(cái)務(wù)管理制度
- 人教版五年級(jí)數(shù)學(xué)下冊(cè)各單元知識(shí)點(diǎn)總結(jié)
- 肌肉注射課件(共45張課件)
- 四牙源性腫瘤課件
- Unit 9 Section B 1a-1d 教學(xué)設(shè)計(jì) 2023-2024學(xué)年人教版英語八年級(jí)下冊(cè)
- 直播違禁詞培訓(xùn)
- 社會(huì)工作行政(第三版)課件匯 時(shí)立榮 第1-5章 社會(huì)服務(wù)機(jī)構(gòu)- 領(lǐng)導(dǎo)與溝通、激勵(lì)
- 2024年全國高級(jí)美發(fā)師技能考試題庫(含答案)
- 拔牙流程四手操作
- 應(yīng)急轉(zhuǎn)貸基金培訓(xùn)
評(píng)論
0/150
提交評(píng)論