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);
上一篇:thinkphp5-图片处理


下一篇:thinkphp5-上传文件