濮阳杆衣贸易有限公司

主頁 > 知識庫 > thinkphp5框架前后端分離項(xiàng)目實(shí)現(xiàn)分頁功能的方法分析

thinkphp5框架前后端分離項(xiàng)目實(shí)現(xiàn)分頁功能的方法分析

熱門標(biāo)簽:沛縣400電話辦理 AI電話機(jī)器人OEM貼牌 江蘇電商外呼系統(tǒng)運(yùn)營商 智能電話機(jī)器人好公司門薩維 青白江地圖標(biāo)注 辦理重慶400電話 銅川電話機(jī)器人價格 聊城電話外呼系統(tǒng)公司 德陽中江如何申請400開頭電話

本文實(shí)例講述了thinkphp5框架前后端分離項(xiàng)目實(shí)現(xiàn)分頁功能的方法。分享給大家供大家參考,具體如下:

方法一

利用tp5提供的paginate方法實(shí)現(xiàn)自動分頁

參數(shù)

page第幾頁,paginate分頁方法會自動獲取

size  每頁數(shù)量

代碼

/**
* Notes:消費(fèi)記錄
* Date: 2019/6/25
* Time: 15:43
* @param Request $request
* @return \think\response\Json
*/
public function getMyConsumeLog(Request $request)
{
    global $_W;
    $size = $request->param('size', 6);
    $list = $this->model->getListByMid($_W['user']['id'],$size);
    return json(['data' => $list, 'error' => 0, 'message' => 'success']);
}
public function getListByMid($mid,$size = 10){
    $res = $this
      ->alias('c')
      ->field('c.*,b.book_name,b.book_flash,s.section_title')
      ->leftJoin('booksection s','c.chapter_id = s.id')
      ->leftJoin('book b','s.book_id = b.id')
      ->where('c.mid',$mid)
      ->order('c.id desc')
      ->paginate($size);
    return $res;
}

返回數(shù)據(jù)

{
    "data": {
        "total": 1,
        "per_page": 1,
        "current_page": 1,
        "last_page": 1,
        "data": [
            {
                "id": 105,
                "mid": 55,
                "book_id": 31,
                "chapter_id": 46046,
                "score": 27,
                "create_time": 1561447448,
                "book_name": "桃運(yùn)村支書",
                "book_flash": "https://cdnxiaoshuo.t.com/FiO6TM0N4kpzKB7tqrDko64ZS4H4",
                "section_title": "第29章 康莊大道"
            }
        ]
    },
    "error": 0,
    "message": "success"
}

方法二

利用limit方法

$curr_page = $request->param('page', 1);
    $size = $request->param('size', 6);
$list = $consume_model->getListByWhere($curr_page, $size, $where);
    $num = $consume_model->getListByWhereCount($where);
    return json(['data' => $list,'num' => $num,'error' => 0, 'message' => 'success']);
public function getListByWhere($curr_page,$limit = 10,$where = null){
    $res = $this
      ->alias('c')
      ->field('c.*,b.book_name,s.section_title')
      ->leftJoin('booksection s','c.chapter_id = s.id')
      ->leftJoin('book b','s.book_id = b.id')
      ->where($where)
      ->order('c.id desc')
      ->limit($limit*($curr_page - 1),$limit)
      ->select()
      ->toArray();
    return $res;
}
public function getListByWhereCount($where = null){
    $count = $this
      ->alias('c')
      ->where($where)
      ->count();
    return $count;
}

返回值

{
    "data": [
        {
            "id": 2,
            "mid": 4,
            "book_id": 4,
            "chapter_id": 22,
            "score": 30,
            "create_time": 0,
            "book_name": "復(fù)仇者聯(lián)盟I",
            "section_title": "第11章  你是睡"
        },
        {
            "id": 1,
            "mid": 4,
            "book_id": 29,
            "chapter_id": 34,
            "score": 20,
            "create_time": 1598999,
            "book_name": "復(fù)仇者聯(lián)盟II",
            "section_title": "第11章  你是睡"
        }
    ],
    "num": 2,
    "total_coin": 50,
    "error": 0,
    "message": "success"
}

更多關(guān)于thinkPHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《ThinkPHP入門教程》、《thinkPHP模板操作技巧總結(jié)》、《ThinkPHP常用方法總結(jié)》、《codeigniter入門教程》、《CI(CodeIgniter)框架進(jìn)階教程》、《Zend FrameWork框架入門教程》及《PHP模板技術(shù)總結(jié)》。

希望本文所述對大家基于ThinkPHP框架的PHP程序設(shè)計有所幫助。

您可能感興趣的文章:
  • ThinkPHP5.1+Ajax實(shí)現(xiàn)的無刷新分頁功能示例
  • thinkphp5+layui實(shí)現(xiàn)的分頁樣式示例
  • ThinkPHP5&5.1框架關(guān)聯(lián)模型分頁操作示例
  • thinkPHP5框架分頁樣式類完整示例
  • thinkPHP5框架實(shí)現(xiàn)基于ajax的分頁功能示例
  • thinkPHP5分頁功能實(shí)現(xiàn)方法分析
  • ThinkPHP5分頁paginate代碼實(shí)例解析

標(biāo)簽:赤峰 鷹潭 烏魯木齊 山南 濟(jì)寧 三亞 迪慶 南寧

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《thinkphp5框架前后端分離項(xiàng)目實(shí)現(xiàn)分頁功能的方法分析》,本文關(guān)鍵詞  thinkphp5,框架,前,后端,分離,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《thinkphp5框架前后端分離項(xiàng)目實(shí)現(xiàn)分頁功能的方法分析》相關(guān)的同類信息!
  • 本頁收集關(guān)于thinkphp5框架前后端分離項(xiàng)目實(shí)現(xiàn)分頁功能的方法分析的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    桂平市| 红桥区| 贺州市| 广河县| 将乐县| 顺昌县| 安仁县| 上栗县| 兴和县| 武城县| 定结县| 渑池县| 长阳| 老河口市| 兰考县| 大理市| 本溪市| 平阴县| 唐海县| 兴城市| 双桥区| 蓬溪县| 夏河县| 澄城县| 宁强县| 阳信县| 肃宁县| 拜城县| 定结县| 蓬莱市| 鸡泽县| 云南省| 柳林县| 常德市| 内丘县| 读书| 筠连县| 中卫市| 贵州省| 神木县| 酒泉市|