使用Thinkphp5实现分页很是简便。
具体请参考官方文档: http://www.kancloud.cn/manual/thinkphp5/154294
1. 使用Query.php的paginate 接口获取数据内容,通过render接口获取渲染内容
thinkphp/library/think/db/Query.php
thinkphp/library/think/paginator/Collection.php
thinkphp/library/think/paginator/driver/Bootstrap.php ==》该文件实现了保存当前页号,生成渲染内容
public function index(){
$listrows=config("LISTROWS")?config("LISTROWS"):10;
$project_infos=model("Project")->paginate($listrows);
$project_lists=$project_infos->toArray()['data'];
$this->assign("project_infos",$project_lists);
$this->assign("page",$project_infos->render());
return $this->fetch();
}打印log可以发现$project_infos->render() 即为html页面中页数
然后只需在html 中引用$page 即可
<div> {$page}</div>之后显示效果就出来了,因为render() 生成的渲染内容包含了页数对应的链接,所以我们点击页数的时候会再次进入这个控制器,并传人当前的页数号。
本文介绍如何在ThinkPHP5框架中实现分页功能。通过使用Query.php的paginate接口获取数据,利用render接口生成HTML页面中的分页链接。点击页码会自动跳转并更新页面内容。

766

被折叠的 条评论
为什么被折叠?



