婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > 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實現分頁功能示例的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 黄冈市| 井冈山市| 栖霞市| 茂名市| 长春市| 彭州市| 克山县| 曲麻莱县| 达拉特旗| 临潭县| 阿拉善左旗| 尼勒克县| 金川县| 胶州市| 聂拉木县| 汉阴县| 根河市| 九江市| 阳朔县| 修武县| 吉首市| 长沙县| 广水市| 临桂县| 辽宁省| 怀柔区| 辉县市| 二连浩特市| 柳州市| 牙克石市| 镇远县| 讷河市| 连城县| 府谷县| 中宁县| 垫江县| 鹤峰县| 威海市| 沂南县| 包头市| 克拉玛依市|