栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > PHP

thinkPHP5.1框架使用SemanticUI实现分页功能示例

PHP 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

thinkPHP5.1框架使用SemanticUI实现分页功能示例

本文实例讲述了thinkPHP5.1框架使用SemanticUI实现分页功能。分享给大家供大家参考,具体如下:

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

 'Semantic',
    'var_page' => 'page',
  ];

2、thinkphplibrarythinkpaginatordriver下新建Semantic.php,下面是文件的内容

';
  private static $nextButtonHtml = '';
  
  protected function getPreviousButton() {
    if ($this->currentPage() <= 1) {
      return $this->getDisabledTextWrapper(Semantic::$previousButtonHtml);
    }
    $url = $this->url(
      $this->currentPage() - 1
    );
    return $this->getPagelinkWrapper($url, Semantic::$previousButtonHtml);
  }
  
  protected function getNextButton() {
    if (!$this->hasMore) {
      return $this->getDisabledTextWrapper(Semantic::$nextButtonHtml);
    }
    $url = $this->url($this->currentPage() + 1);
    return $this->getPagelinkWrapper($url, Semantic::$nextButtonHtml);
  }
  
  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;
  }
  
  public function render() {
    if ($this->hasPages()) {
      if ($this->simple){
 return sprintf(
   '%s %s',
   $this->getPreviousButton(),
   $this->getNextButton()
 );
      }else{
 return sprintf(
   '%s %s %s',
   $this->getPreviousButton(),
   $this->getlinks(),
   $this->getNextButton()
 );
      }
    }
    return null;
  }
  
  protected function getAvailablePageWrapper($url, $page) {
    return '' . $page . '';
  }
  
  protected function getDisabledTextWrapper($text) {
    return '' . $text . '';
  }
  
  protected function getActivePageWrapper($text) {
    return '' . $text . '';
  }
  
  protected function getDots() {
    return $this->getDisabledTextWrapper('...');
  }
  
  protected function getUrllinks(array $urls) {
    $html = '';
    foreach ($urls as $page => $url) {
      $html .= $this->getPagelinkWrapper($url, $page);
    }
    return $html;
  }
  
  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程序设计有所帮助。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/39031.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号