zoukankan      html  css  js  c++  java
  • thinkphp6 paginate() 分页数据处理后输出

    来源:https://blog.csdn.net/baidu_29994443/article/details/101070031

    替换处理

    <?php
    //model里面的分页函数
    public function pageQuery(){    
        $rs = $this->where($where)->field(true)->order('id desc')->paginate()
        ->each(function($item, $key){
            if($item['status']==1){
                $item['name1'] = $item['name2'];
            }
            $item['imgSize'] = round($item['imgSize']/1024/1024,2);
            return $item;
        });
        return $rs;
    }
    ?>

    如果each里面涉及到别的表,则代码如下:

    <?php
    //model里面的分页函数
    public function pageQuery(){    
        $rs = $this->where($where)->field(true)->order('id desc')->paginate()   
        ->each(function($item, $key){
            $urs = Db::name('u')->where('isShow',1)->select();
            foreach ($urs as $rkey=>$rv){
                if($item['userScore']>=$rv['startScore'] && $item['userScore']<$rv['endScore']){
                   $item['userRank'] = $rv['rankName'];
                }
            }
            return $item;
        });
        return $rs;
    }
    ?>

    如果each里面涉及到外部参数,则代码如下:

    <?php
    //model里面的分页函数
    public function pageQuery(){
    //从别的表获得参数值,一次获取,each中可以重复使用
    $urs = Db::name('u')->where('isShow',1)->select(); 
    $rs = $this->where($where)->field(true)->order('id desc')->paginate() 
    ->each(function($item, $key) use ($urs){ 
    //使用外部传来的参数$urs
    foreach ($urs as $rkey=>$rv){
    if($item['userScore']>=$rv['startScore'] && $item['userScore']<$rv['endScore']){
      $item['userRank'] = $rv['rankName'];
    }
    }
    return $item;
    });
    return $rs;
    }
    ?>
  • 相关阅读:
    leetcode 第二题Add Two Numbers java
    二叉树中的那些常见的面试题(转)
    运行的指令
    Python常见经典 python中if __name__ == '__main__': 的解析
    软件测试基本概念
    JAVA Android王牌教程
    17个新手常见Python运行时错误
    QTP
    链表有关的常见面试题
    Robot Framework and Ride
  • 原文地址:https://www.cnblogs.com/laijinquan/p/13780565.html
Copyright © 2011-2022 走看看