thinkPHP5.1框架使用SemanticUI實(shí)現(xiàn)分頁功能示例
本文實(shí)例講述了thinkPHP5.1框架使用SemanticUI實(shí)現(xiàn)分頁功能。分享給大家供大家參考,具體如下:
1、config目錄下新建paginate.php,下面是文件的內(nèi)容
<?php //分頁配置 return [ 'type' => 'Semantic', 'var_page' => 'page', ];
2、thinkphp\library\think\paginator\driver\下新建Semantic.php,下面是文件的內(nèi)容
<?php /** * Created by alic(AlicFeng) on 17-6-15 下午9:17 from PhpStorm. * Email is alic@samego.com */ namespace think\paginator\driver; use think\Paginator; class Semantic extends Paginator { private static $previousButtonHtml = '<i class="icon left arrow"></i>'; private static $nextButtonHtml = '<i class="icon right arrow"></i>'; /** * 上一頁按鈕 * @return string */ protected function getPreviousButton() { if ($this->currentPage() <= 1) { return $this->getDisabledTextWrapper(Semantic::$previousButtonHtml); } $url = $this->url( $this->currentPage() - 1 ); return $this->getPageLinkWrapper($url, Semantic::$previousButtonHtml); } /** * 下一頁按鈕 * @return string */ protected function getNextButton() { if (!$this->hasMore) { return $this->getDisabledTextWrapper(Semantic::$nextButtonHtml); } $url = $this->url($this->currentPage() + 1); return $this->getPageLinkWrapper($url, Semantic::$nextButtonHtml); } /** * 頁碼按鈕 * @return string */ protected function getLinks() { $block = [ 'first' => null, 'slider' => null, 'last' => null ]; $side = 3; $window = $side * 2; if ($this->lastPage < $window + 6) { $block['first'] = $this->getUrlRange(1, $this->lastPage); } elseif ($this->currentPage <= $window) { $block['first'] = $this->getUrlRange(1, $window + 2); $block['last'] = $this->getUrlRange($this->lastPage - 1, $this->lastPage); } elseif ($this->currentPage > ($this->lastPage - $window)) { $block['first'] = $this->getUrlRange(1, 2); $block['last'] = $this->getUrlRange($this->lastPage - ($window + 2), $this->lastPage); } else { $block['first'] = $this->getUrlRange(1, 2); $block['slider'] = $this->getUrlRange($this->currentPage - $side, $this->currentPage + $side); $block['last'] = $this->getUrlRange($this->lastPage - 1, $this->lastPage); } $html = ''; if (is_array($block['first'])) { $html .= $this->getUrlLinks($block['first']); } if (is_array($block['slider'])) { $html .= $this->getDots(); $html .= $this->getUrlLinks($block['slider']); } if (is_array($block['last'])) { $html .= $this->getDots(); $html .= $this->getUrlLinks($block['last']); } return $html; } /** * 渲染分頁html * @return mixed */ public function render() { if ($this->hasPages()) { if ($this->simple){ return sprintf( '<div style="text-align: center"><div class="ui pagination menu">%s %s</div></div>', $this->getPreviousButton(), $this->getNextButton() ); }else{ return sprintf( '<div style="text-align: center"><div class="ui pagination menu">%s %s %s</div></div>', $this->getPreviousButton(), $this->getLinks(), $this->getNextButton() ); } } return null; } /** * 生成一個(gè)可點(diǎn)擊的按鈕 * * @param string $url * @param int $page * @return string */ protected function getAvailablePageWrapper($url, $page) { return '<a href="' . htmlentities($url) . '" rel="external nofollow" class="item">' . $page . '</a>'; } /** * 生成一個(gè)禁用的按鈕 * * @param string $text * @return string */ protected function getDisabledTextWrapper($text) { return '<a class="disabled item">' . $text . '</a>'; } /** * 生成一個(gè)激活的按鈕 * * @param string $text * @return string */ protected function getActivePageWrapper($text) { return '<a class="active item">' . $text . '</a>'; } /** * 生成省略號(hào)按鈕 * * @return string */ protected function getDots() { return $this->getDisabledTextWrapper('...'); } /** * 批量生成頁碼按鈕. * * @param array $urls * @return string */ protected function getUrlLinks(array $urls) { $html = ''; foreach ($urls as $page => $url) { $html .= $this->getPageLinkWrapper($url, $page); } return $html; } /** * 生成普通頁碼按鈕 * * @param string $url * @param int $page * @return string */ protected function getPageLinkWrapper($url, $page) { if ($page == $this->currentPage()) { return $this->getActivePageWrapper($page); } return $this->getAvailablePageWrapper($url, $page); } }
3、搞定
更多關(guān)于thinkPHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《ThinkPHP入門教程》、《thinkPHP模板操作技巧總結(jié)》、《ThinkPHP常用方法總結(jié)》、《codeigniter入門教程》、《CI(CodeIgniter)框架進(jìn)階教程》、《Zend FrameWork框架入門教程》及《PHP模板技術(shù)總結(jié)》。
希望本文所述對大家基于ThinkPHP框架的PHP程序設(shè)計(jì)有所幫助。
- tp5框架無刷新分頁實(shí)現(xiàn)方法分析
- tp5框架內(nèi)使用tp3.2分頁的方法分析
- ThinkPHP5.1+Ajax實(shí)現(xiàn)的無刷新分頁功能示例
- thinkphp5框架前后端分離項(xiàng)目實(shí)現(xiàn)分頁功能的方法分析
- thinkphp5+layui實(shí)現(xiàn)的分頁樣式示例
- ThinkPHP5&5.1框架關(guān)聯(lián)模型分頁操作示例
- thinkPHP5框架分頁樣式類完整示例
- thinkPHP5框架實(shí)現(xiàn)基于ajax的分頁功能示例
- thinkPHP5框架實(shí)現(xiàn)分頁查詢功能的方法示例
- thinkPHP5使用laypage分頁插件實(shí)現(xiàn)列表分頁功能
- thinkPHP5分頁功能實(shí)現(xiàn)方法分析
- TP5框架實(shí)現(xiàn)自定義分頁樣式的方法示例
相關(guān)文章
thinkPHP+mysql+ajax實(shí)現(xiàn)的仿百度一下即時(shí)搜索效果詳解
這篇文章主要介紹了thinkPHP+mysql+ajax實(shí)現(xiàn)的仿百度一下即時(shí)搜索效果,結(jié)合完整實(shí)例形式詳細(xì)分析了thinkPHP+mysql+ajax實(shí)現(xiàn)的仿百度一下即時(shí)搜索效果具體數(shù)據(jù)表、控制器、前臺(tái)視圖與樣式相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2019-07-07PHP+jQuery+Ajax實(shí)現(xiàn)分頁效果 jPaginate插件的應(yīng)用
這篇文章主要介紹了PHP+jQuery+Ajax實(shí)現(xiàn)分頁效果,以及jPaginate插件的應(yīng)用2015-10-10php將數(shù)據(jù)庫中的電話號(hào)碼讀取出來并生成圖片
本PHP程序作用是從數(shù)據(jù)庫中讀取出手機(jī)號(hào)碼或其他數(shù)據(jù)并生成圖片,起到干擾采集防采集的作用。(英文或數(shù)字,如果要支持中文的話需要額外添加字庫)。本代碼為原創(chuàng)代碼。2008-08-08PHP開發(fā)框架Laravel數(shù)據(jù)庫操作方法總結(jié)
這篇文章主要介紹了PHP開發(fā)框架Laravel數(shù)據(jù)庫操作方法總結(jié),包含Select查詢、Insert語句、update語句、Delete語句、事務(wù)等,需要的朋友可以參考下2014-09-09thinkPHP框架對接支付寶即時(shí)到賬接口回調(diào)操作示例
這篇文章主要介紹了thinkPHP框架對接支付寶即時(shí)到賬接口回調(diào)操作,結(jié)合實(shí)例形式分析了thinkPHP針對支付寶接口回調(diào)操作的原理與具體操作步驟,需要的朋友可以參考下2016-11-11