使用ThinkPHP8分页时报如下错误:
think\\db\\BaseQuery::paginate(): Argument #1 ($listRows) must be of type array|int|null, string given, called in D:\\ProgramFiles\\phpstudy_pro\\WWW\\tp8.cc\\app\\union\\controller\\Role.php on line 44
仔细看下下方代码,看着是没问题的。
//获取每页显示的条数
$limit= $request->param('limit');
//获取当前页数
$page= $request->param('page');
$where=[];
$role_list=Roles::where($where)
->order('id', 'desc')
->paginate($limit,false,['page'=>$page])
->toArray();最后发现问题是paginate()中的参数要求是int类型,而$limit接收过来的string类型,这里只要对其进行转换为int即可.
正确的代码如下:
//获取每页显示的条数
$limit= $request->param('limit');
//获取当前页数
$page= $request->param('page');
$where=[];
$role_list=Roles::where($where)
->order('id', 'desc')
->paginate((int)$limit,false,['page'=>$page])
->toArray()
关于简忆
简忆诞生的故事



粤ICP备16092285号
文章评论(0)