




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
第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等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(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ǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 緊急國際合同審查、翻譯認(rèn)證及法律效力合同
- 既有建筑消防設(shè)施優(yōu)化升級(jí)補(bǔ)充合同
- 外資保險(xiǎn)公司中國理賠業(yè)務(wù)風(fēng)險(xiǎn)評估與合同
- 親子關(guān)系修復(fù)子女探視協(xié)議書
- 網(wǎng)絡(luò)文學(xué)作品翻譯及工作室租賃商務(wù)合作框架協(xié)議
- 海洋運(yùn)輸貨物保險(xiǎn)責(zé)任及索賠處理合同
- 雨天安全健康教育
- 共享健身房運(yùn)營管理補(bǔ)充協(xié)議
- 建筑工程安全認(rèn)證與現(xiàn)場管理協(xié)議
- 商業(yè)綜合體導(dǎo)視系統(tǒng)委托經(jīng)營及廣告投放管理合同
- 水資源應(yīng)急調(diào)度模型-洞察分析
- DB51-T 3000-2023 退役軍人服務(wù)站建設(shè)與運(yùn)行管理規(guī)范
- 神經(jīng)指南:中國成人失眠診斷與治療指南(2017版)
- 代理商合作條件說明
- DB11-T 1952-2022 地理國情監(jiān)測技術(shù)規(guī)程
- GB/T 15843.2-2024網(wǎng)絡(luò)安全技術(shù)實(shí)體鑒別第2部分:采用鑒別式加密的機(jī)制
- 完整版:美制螺紋尺寸對照表(牙數(shù)、牙高、螺距、小徑、中徑外徑、鉆孔)
- 陪診服務(wù)協(xié)議
- 2023年廣東深圳中考滿分作文《把學(xué)到的東西用起來真有意義》
- 2024年湖南省衡陽八中教育集團(tuán)直選生數(shù)學(xué)模擬試卷+
- 胸痛規(guī)范化評估與診斷中國專家共識(shí)(全文)
評論
0/150
提交評論