校园春色亚洲色图_亚洲视频分类_中文字幕精品一区二区精品_麻豆一区区三区四区产品精品蜜桃

主頁 > 知識庫 > thinkPHP5.1框架使用SemanticUI實現分頁功能示例

thinkPHP5.1框架使用SemanticUI實現分頁功能示例

熱門標簽:仁和怎么申請400開頭的電話 高德地圖標注家 哪里辦理400電話 江西手機自動外呼防封系統是什么 怎么向銷售公司推銷外呼系統 長春人工外呼系統服務商 廣州防封卡外呼系統多少錢一個月 外呼系統撥打暫時無法接通 廣東地市地圖標注

本文實例講述了thinkPHP5.1框架使用SemanticUI實現分頁功能。分享給大家供大家參考,具體如下:

1、config目錄下新建paginate.php,下面是文件的內容

?php
//分頁配置
return
  [
    'type' => 'Semantic',
    'var_page' => 'page',
  ];

2、thinkphp\library\think\paginator\driver\下新建Semantic.php,下面是文件的內容

?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;
  }
  /**
   * 生成一個可點擊的按鈕
   *
   * @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>';
  }
  /**
   * 生成一個禁用的按鈕
   *
   * @param string $text
   * @return string
   */
  protected function getDisabledTextWrapper($text) {
    return 'a class="disabled item">' . $text . '/a>';
  }
  /**
   * 生成一個激活的按鈕
   *
   * @param string $text
   * @return string
   */
  protected function getActivePageWrapper($text) {
    return 'a class="active item">' . $text . '/a>';
  }
  /**
   * 生成省略號按鈕
   *
   * @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、搞定

更多關于thinkPHP相關內容感興趣的讀者可查看本站專題:《ThinkPHP入門教程》、《thinkPHP模板操作技巧總結》、《ThinkPHP常用方法總結》、《codeigniter入門教程》、《CI(CodeIgniter)框架進階教程》、《Zend FrameWork框架入門教程》及《PHP模板技術總結》。

希望本文所述對大家基于ThinkPHP框架的PHP程序設計有所幫助。

您可能感興趣的文章:
  • tp5框架無刷新分頁實現方法分析
  • tp5框架內使用tp3.2分頁的方法分析
  • ThinkPHP5.1+Ajax實現的無刷新分頁功能示例
  • thinkphp5框架前后端分離項目實現分頁功能的方法分析
  • thinkphp5+layui實現的分頁樣式示例
  • ThinkPHP5&5.1框架關聯模型分頁操作示例
  • thinkPHP5框架分頁樣式類完整示例
  • thinkPHP5框架實現基于ajax的分頁功能示例
  • thinkPHP5框架實現分頁查詢功能的方法示例
  • thinkPHP5使用laypage分頁插件實現列表分頁功能
  • thinkPHP5分頁功能實現方法分析
  • TP5框架實現自定義分頁樣式的方法示例

標簽:梅河口 惠州 廈門 文山 黔東 湘西 濮陽 海北

巨人網絡通訊聲明:本文標題《thinkPHP5.1框架使用SemanticUI實現分頁功能示例》,本文關鍵詞  thinkPHP5.1,框架,使用,SemanticUI,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《thinkPHP5.1框架使用SemanticUI實現分頁功能示例》相關的同類信息!
  • 本頁收集關于thinkPHP5.1框架使用SemanticUI實現分頁功能示例的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 会同县| 漯河市| 上栗县| 东乡县| 富顺县| 剑川县| 连城县| 中山市| 吐鲁番市| 渝中区| 宜宾县| 宽甸| 屏东市| 获嘉县| 衡水市| 务川| 大港区| 大邑县| 阳信县| 汶上县| 合水县| 英德市| 铜川市| 龙川县| 汝阳县| 左权县| 贵州省| 巩留县| 康乐县| 福贡县| 峡江县| 浦城县| 彭水| 萝北县| 双辽市| 宁乡县| 思茅市| 偃师市| 全州县| 涿州市| 宣恩县|