编程语言
首页 > 编程语言> > thinkphp5-分页

thinkphp5-分页

作者:互联网

用法

控制器

<?php
namespace app\index\controller;

use think\Controller;

class Index extends Controller
{

    public function index()
    {
        $users = model('user')->where('status',1)->paginate(['var_page'=>'page','list_rows'=>2]);
        dump($users->toArray());
    }
}

测试访问(page当前分页)

http://www.tp5.com/index.php/index/index/index/page/3

结果

array(5) {
  ["total"] => int(10)
  ["per_page"] => int(3)
  ["current_page"] => int(3)
  ["last_page"] => int(4)
  ["data"] => array(3) {
    [0] => array(3) {
      ["id"] => int(13)
      ["name"] => string(10) "胡勇健1"
      ["status"] => int(1)
    }
    [1] => array(3) {
      ["id"] => int(15)
      ["name"] => string(10) "胡勇健1"
      ["status"] => int(1)
    }
    [2] => array(3) {
      ["id"] => int(17)
      ["name"] => string(10) "胡勇健1"
      ["status"] => int(1)
    }
  }
}

其他写法

$users = model('user')->where('status',1)->paginate(2);

标签:status,index,分页,10,int,thinkphp5,array,page
来源: https://www.cnblogs.com/hu308830232/p/15491802.html