专栏名称: 网页设计轻松学
网页设计与制作技术,php、html javascript、网站开发技术的交流与学习。PS AI平面网页设计,修图等相关学习应有尽有!!
目录
相关文章推荐
半导体行业联盟  ·  华为6500字通报 ·  昨天  
半导体行业联盟  ·  哈萨克斯坦首颗芯片点亮!RISC-V架构! ·  昨天  
OFweek维科网  ·  笔电OLED面板出货排名:三星第一,和辉第二 ... ·  3 天前  
半导体行业联盟  ·  从卖车发工资到全球第一!利润大增26倍,思特 ... ·  4 天前  
半导体行业联盟  ·  今天,铭记中国芯片之母---黄令仪! ·  5 天前  
51好读  ›  专栏  ›  网页设计轻松学

Thinkphp5.0分页和跳页

网页设计轻松学  · 公众号  ·  · 2018-02-08 07:29

正文

后台查询商品或者会员量需要用到分页展示列表,当页数比较多的时候为了体高用户体验度,需要添加一个跳页也就是手动输入页码数进行快速跳转指定页面。由于手动编写分页比较麻烦,又想使用TP5自带的分页,但是TP5自带的分页类比较简单,所以可以通过修改Bootstrap类自定义显示分页的页码和数量。

由于Bootstrap类是tp自带的类,所以为了我们尽量不要改动底层自带的类,这里拷贝一下Bootstrap类然后重命名为BootstrapDetailed.php,目录结构如图:

代码如下:

  1. // +----------------------------------------------------------------------

  2. // | ThinkPHP [ WE CAN DO IT JUST THINK ]

  3. // +----------------------------------------------------------------------

  4. // | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved.

  5. // +----------------------------------------------------------------------

  6. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )

  7. // +----------------------------------------------------------------------

  8. // | Author: zhangyajun <[email protected]>

  9. // +----------------------------------------------------------------------


  10. namespace think\paginator\driver;


  11. use think\Paginator;


  12. class BootstrapDetailed extends Paginator

  13. {


  14.    /**

  15.     * 上一页按钮

  16.     * @param string $text

  17.     * @return string

  18.     */

  19.    protected function getPreviousButton($text = "上一页")

  20.    {


  21.        if ($this->currentPage() <= 1) {

  22.            return $this->getDisabledTextWrapper($text);

  23.        }


  24.        $url = $this->url(

  25.            $this->currentPage() - 1

  26.        );


  27.        return $this->getPageLinkWrapper($url, $text);

  28.    }




  29.    //总数标签

  30.    protected  function totalshow()

  31.    {


  32.        $totalhtml="

  33. 共".$this->total."条记录  第".$this->currentPage()."页/共".$this->lastPage()."页
  34. ";

  35.        return $totalhtml;


  36.    }


  37.    //尾页标签


  38.    protected  function showlastpage($text = '尾页')

  39.    {


  40.        if($this->currentPage()==$this->lastPage())

  41.        {

  42.            return $this->getDisabledTextWrapper($text);


  43.        }


  44.        $url = $this->url($this->lastPage());

  45.        return $this->getPageLinkWrapper($url, $text);

  46.    }


  47.    //首页标签


  48.    protected  function showfirstpage($text = '首页')

  49.    {


  50.        if ($this->currentPage()==1)

  51.        {

  52.            return $this->getDisabledTextWrapper($text);


  53.        }


  54.        $url = $this->url(1);

  55.        return $this->getPageLinkWrapper($url, $text);

  56.    }

  57.    //后五页

  58.    protected  function afivepage($text = '后五页')

  59.    {



  60.        if($this->lastPage()currentPage()+5)

  61.        {

  62.            return $this->getDisabledTextWrapper($text);


  63.        }

  64.        $url = $this->url($this->currentPage()+5);



  65.        return $this->getPageLinkWrapper($url, $text);

  66.    }


  67.    //前五页

  68.    protected  function bfivepage($text = '前五页')

  69.    {



  70.        if($this->currentPage()<5)

  71.        {

  72.            return $this->getDisabledTextWrapper($text);


  73.        }

  74.        $url = $this->url($this->currentPage()-5);



  75.        return $this->getPageLinkWrapper($url, $text);

  76.    }



  77.    /**

  78.     * 下一页按钮

  79.     * @param string $text

  80.     * @return string

  81.     */

  82.    protected function getNextButton($text = '下一页')

  83.    {

  84.        if (!$this->hasMore) {

  85.            return $this->getDisabledTextWrapper($text);

  86.        }


  87.        $url = $this->url($this->currentPage() + 1);


  88.        return $this->getPageLinkWrapper($url, $text);

  89.    }


  90.    //跳转到哪页

  91.    protected  function gopage()

  92.    {



  93.        return $gotohtml="

  94. ";

  95.        // return $totalhtml;;


  96.    }


  97.    /**

  98.     * 页码按钮

  99.     * @return string

  100.     */

  101.    protected function getLinks()

  102.    {

  103.        if ($this->simple)

  104.            return '';


  105.        $block = [

  106.            'first'  => null,

  107.            'slider' => null,

  108.            'last'   => null

  109.        ];


  110.        $side   = 2;

  111.        $window = $side * 2;


  112.        if ($this->lastPage < $window +1) {

  113.            $block['slider'] = $this->getUrlRange(1, $this->lastPage);


  114.        } elseif ($this->currentPage <= $window-1) {


  115.            $block['slider'] = $this->getUrlRange(1, $window +







请到「今天看啥」查看全文