>[success] ### 第三難 ThinkPHP自定義分頁模板
>[info] ### 默認分頁模板

>[info] ### 自定義分頁模板
* 項目鏈接:http://pan.baidu.com/s/1miIIcmG 密碼:wwnl

~~~php
<?php
namespace tool;
use think\Paginator;
class TpPageHelper extends Paginator
{
//TODO : 中間按鈕個數
protected $bnumber = 10;
//TODO : 首頁
protected function getfirstButton($str = '')
{
if ($this->currentPage() <= 1) {
return $this->getDisabledTextWrapper($str);
}
$url = $this->url(1);
return $this->getPageLinkWrapper($url, $str);
}
//TODO : 上一頁
protected function getPreviousButton($text = "«")
{
if ($this->currentPage() <= 1) {
return $this->getDisabledTextWrapper($text);
}
$url = $this->url(
$this->currentPage() - 1
);
return $this->getPageLinkWrapper($url, $text);
}
//TODO : 頁碼
protected function getLinks()
{
if ($this->total > $this->listRows) {
if ($this->lastPage < $this->bnumber) {
return $this->getUrlLinks($this->getUrlRange(1, $this->lastPage));
} else {
$min = 1;
if ($this->currentPage > $this->bnumber / 2) $min = $this->currentPage - floor($this->bnumber / 2);
if ($this->lastPage - $this->currentPage < $this->bnumber / 2) $min = $this->lastPage - $this->bnumber + 1;
return $this->getUrlLinks($this->getUrlRange($min, $min + $this->bnumber - 1));
}
}
}
//TODO : 下一頁
protected function getNextButton($text = '»')
{
if (!$this->hasMore) {
return $this->getDisabledTextWrapper($text);
}
$url = $this->url($this->currentPage() + 1);
return $this->getPageLinkWrapper($url, $text);
}
//TODO : 末頁
protected function getlastButton($text = '')
{
if (!$this->hasMore) {
return $this->getDisabledTextWrapper($text);
}
$url = $this->url($this->lastPage());
return $this->getPageLinkWrapper($url, $text);
}
//TODO : 渲染頁
public function render()
{
//數據是否足夠分頁
if ($this->hasPages()) {
return sprintf(
'<ul class="btn-item fr">%s %s %s %s %s</ul>',
$this->getfirstButton('首頁'),
$this->getPreviousButton('上一頁'),
$this->getLinks(),
$this->getNextButton('下一頁'),
$this->getlastButton('末頁')
);
}
}
//TODO : 生成禁用按鈕
protected function getDisabledTextWrapper($text)
{
return '<li class="disabled"><span>' . $text . '</span></li>';
}
//TODO : 生成普通按鈕
protected function getPageLinkWrapper($url, $page)
{
if ($page == $this->currentPage()) {
return $this->getActivePageWrapper($page);
}
return $this->getAvailablePageWrapper($url, $page);
}
//TODO : 生成當前頁按鈕
protected function getActivePageWrapper($text)
{
return '<li class="active"><span>' . $text . '</span></li>';
}
//TODO : 可點擊按鈕
protected function getAvailablePageWrapper($url, $page)
{
return '<li><a href="' . htmlentities($url) . '">' . $page . '</a></li>';
}
//TODO : 批量生成頁碼按鈕
protected function getUrlLinks(array $urls)
{
$html = '';
foreach ($urls as $page => $url) {
$html .= $this->getPageLinkWrapper($url, $page);
}
return $html;
}
}
~~~
* 將 TpPageHelper.php 放在extend\tool下

* 修改默認模板

- 西天取經(九九八十一難)
- 第一難 WebUpload文件上傳
- 第二難 UEditor文本編輯器
- 第三難 ThinkPHP自定義分頁模板
- 第四難 VerificationCode驗證碼
- 第五難 遞歸 尾遞歸 迭代 回調
- 第六難 GRPC服務端和客戶端
- 第七難 PHP小筆記
- 第八難 yum安裝Apache PHP MySQL
- 第九難 高性能MySQL簡介
- 第十難 DIV+CSS簡介
- 十一難 留言板
- 十二難 正則表達式
- 十三難 PHPMailer郵件發送
- 十四難 日歷
- 十五難 百度地圖
- 十六難 加密
- 十七難 篩選url跳轉
- 十八難 圖片轉ASCII碼圖
- 十九難 環境配置
- 二十難 開發工具LiteIDE
- 二一難 開發工具2
- 二二難 準備工作
- 二三難 第一個應用程序 Hello World
- 二四難 語法結構
- 二五難 命名規則
- 二六難 變量
- 二七難 常量
- 二八難 常量計數器 iota
- 二九難 判斷語句if
- 三十難 擇語句switch
- 三一難 循環語句 for
- 三二難 遍歷 range
- 三三難 跳轉語句goto, break, continue
- 三四難 make, len, cap, new, nil
- 三五難 數組 array
- 三六難 切片 slice
- 三七難 集合 map
- 三八難 通道 channel
- 三九難 函數 function
- 四十難 結構 struct
- 四一難 方法 method
- 四二難 接口 interface
- 四三難 指針
- 四四難 異常
- 四五難 模板應用
- 四六難 Go安裝GRPC服務端和客戶端
- 四七難 安裝虛擬機軟件(VirtualBox)
- 四八難 安裝Centos7
- 四九難 --help
- 五十難 目錄文件
- 五一難 系統磁盤
- 五二難 Shell
- 五三難 Nginx安裝配置
- 五四難 PHP安裝配置
- 五五難 MySQL安裝配置
- 五六難 yum 安裝 Apache PHP MySQL
- 五七難 安裝gRPC
- 五八難 安裝memcache
- 五九難 介紹
- 六十難 DIV + CSS
- 六一難 瀏覽器兼容問題
- 六二難 書寫風格(Js中寫Html)
- 六三難 NodeJs(Express框架pug模板引擎)
- 六四難 SQL優化工具SQLAdvisor
- 六五難 JpGraph圖表
- 六六難 日期排序
- 六七難 大部分問題解決方法
- 六八難 小趣味
- 六九難 編程語言排行榜
- 七十難 PHP編輯器
- 七一難 Key
- 七二難 手動定位和自動定位當前文件位置
- 七三難 關閉代碼提示
- 七四難 配置XDebug
- 七五難 配置FTP
- 七六難 配置SSH
- 七七難 Notepad++
- 七八難 XShell 和 Xftp
- 七九難 PHPExcel導入導出
- 八十難 編程科普
- 八一難 ThinkPHP5.1新特性: 容器
- 大雷音寺(領取經書)