thinkphp5-分页

2021/11/1 1:09:42

本文主要是介绍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-分页的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程