码迷,mamicode.com
首页 > 其他好文 > 详细

tp5.0分页样式调控

时间:2018-04-07 01:15:33      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:protected   col   thinkphp   his   new   cte   总数   分页显示   页面   

基础的分页调用

    /**
    *  控制器部分代码
     */
    //实例化模型
    $areasModel=new Areas();
    //分页数据集
    $listarea=$areasModel->paginate($page);
    //分页显示输出
    $page=$listarea->render();
    //模板赋值
    $this->assign(listarea,$listarea);
    $this->assign(page, $page);
    /**
    *  模板页面部分代码
     */
    {$page}//分页输出
    {$listarea->total()}//数据总数
    {$listarea->lastPage()}//总页数
    {$listarea->currentPage()}//当前页

分页类修改,写了三个样式;

    public $rollPage=5;//分页栏每页显示的页数
    public $showPage=12;//总页数超过多少条时显示的首页末页
    /**
     * 分页样式一:首页末页不管何时都显示
     * 
     * 分页样式二:前n页时不显示首页,后n页时不显示末页;n=分页栏数/2(向下取整)
     */
    //样式1和样式2核心代码
    /**
         * 页码按钮
         * @return string
         */
        protected function getLinks()
        {
            if ($this->simple)
                return ‘‘;
            $block = [
                first  => null,
                slider => null,
                last   => null
            ];
            $rollPage = $this->rollPage;//分页栏每页显示的页数
            $nowPage = floor($rollPage/2);//计算分页临时变量
            
            if($this->lastPage <= $rollPage){
                $block[first] = $this->getUrlRange(1, $this->lastPage);
            }else if($this->currentPage <= $nowPage){
                $block[first] = $this->getUrlRange(1, $rollPage);
            }else if($this->currentPage >= ($this->lastPage - $nowPage)){
                $block[first] = $this->getUrlRange($this->lastPage - $rollPage+1, $this->lastPage);
            }else{
                $block[first] = $this->getUrlRange($this->currentPage - $nowPage, $this->currentPage + $nowPage);
            }
            $html = ‘‘;
            if (is_array($block[first])) {
                $html .= $this->getUrlLinks($block[first]);
            }
            return $html;
        }
    /**
     * 分页样式三
     * 按照段分页,具体的效果可以自己下载代码
     * 
     * 例1:1-5,4-8,7-11,...
     * 在第一段时:点击5时跳到下一段
     * 在第二段时:点击8时跳到下一段,点击4时回到上一段
     * 
     * 例2:1-7,6-12,11-17,...
     * 在第二段时:点击12时跳到下一段点击6时回到上一段
     * 在第三段时:点击17时跳到下一段,点击11时回到上一段
     * 
     */
    //核心代码
    /**
         * 页码按钮
         * @return string
         */
        protected function getLinks()
        {
            if ($this->simple)
                return ‘‘;
            $block = [
                first  => null,
                slider => null,
                last   => null
            ];
            $rollPage = $this->rollPage;//分页栏每页显示的页数
            $nowPage = floor($rollPage/2);//计算分页临时变量
            
            if($this->lastPage <= $rollPage){
                $block[first] = $this->getUrlRange(1, $this->lastPage);
            }else if($this->currentPage==0 || $this->currentPage<$rollPage){
                $block[first] = $this->getUrlRange(1, $rollPage);
            }else{
                $n=floor(($this->currentPage+($rollPage-4))/($rollPage-2));
                $start=$n*($rollPage-2)-($rollPage-3);
                $end=$start+$rollPage-1;
                $end=$end>$this->lastPage ? $this->lastPage : $end;
                $block[first] = $this->getUrlRange($start,$end);
            }
            $html = ‘‘;
            if (is_array($block[first])) {
                $html .= $this->getUrlLinks($block[first]);
            }
            return $html;
        }

样式一图:

技术分享图片

样式二图:

技术分享图片

样式三图:

技术分享图片

 

tp5.0分页样式调控

标签:protected   col   thinkphp   his   new   cte   总数   分页显示   页面   

原文地址:https://www.cnblogs.com/comeping/p/8729365.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!