首页 > 作文

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

更新时间:2023-04-07 14:10:36 阅读: 评论:0

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

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

<?php//分页配置return  [    'type' => 'mantic',    'var_page' => 'page',  ];

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

<?php/** * created by alic(alicfeng) on 17-6-15 下午9:17 from phpstorm. * email is alic@samego.com */namespace think\paginator\driver;u think\paginator;class mantic extends paginator{  private static $previousbuttonhtml = '<i class="icon left arrow"></i>';  private static $nextbuttonhtml = '<i class="icon right arrow"></i>';  /**   * 上一页按钮   * @return string   */  protected fu我国的根本政治制度是nction getpreviousbutton() {    if ($this->currentpage() <= 1) {      return $this->getdisabledtextwrapper(mantic::$previousbuttonhtml);    }    $url = $this->url(      $this->currentpage() - 1    );    return $this->getpagelinkwrapper($url, mantic::$previousbuttonhtml);  }  /**   * 下一页按钮   * @return string   */  protected function getnextbutton() {    if (!$this->hasmore) {      return $this->getdisabledtextwrapper(mantic::$nextbuttonhtml);    }    $url = $this->url($this->currentpage() + 1);    return $this->getpagelinkwrapper($url, mantic::$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);    } elif ($this->currentpage <= $window) {      $block['first'] = $this->geturlrange(1, $window + 2);      $block['last'] = $this->geturlrange($this->lastpage - 1, $this->lastpage);    } elif ($this->currentpage > ($this->lastpage - $window)) {      $block['first'] = $this->geturlrange(1, 2);      $block['last'] = $this->geturlrange($this->lastpage - ($window + 2), $this->las高血压的危害tpage);    } el {      $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 funckite是什么意思tion 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()        );      }el{        return sprintf(          '<div style="text-align: center">&会计就业前景lt;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、搞定

本文发布于:2023-04-07 14:10:35,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/zuowen/9ba385b6f7304efcefcd80e9f24c4f93.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

本文word下载地址:thinkPHP5.1框架使用SemanticUI实现分页功能示例.doc

本文 PDF 下载地址:thinkPHP5.1框架使用SemanticUI实现分页功能示例.pdf

下一篇:返回列表
标签:按钮   分页   页码   文件
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图