TP5报错Indirectmodificationofoverloadedelementofthink\paginator\Collectionhasnoeffect
标签:
thinkphptp5 |
分类: 语言程序 |
TP5报如下的错误 Indirect modification of overloaded element of
think\paginator\Collection has no effect
$data[$key]['key'] = $key;
控制器中关键代码如下:
// 查询状态为1的用户数据 并且每页显示10条数据
$list =
Db::name('user')->where('status',1)->paginate(10);
// 把分页数据赋值给模板变量list
$this->assign('list', $list);
// 渲染模板输出
return $this->fetch();
模板文件中分页输出代码如下:
上面的方法非常简单,但是如果我想在查询出来的数据中加入新的值的,上面的方法就不能用了,当你尝试对$list进行循环的时候,会报如下的错误
Indirect modification of overloaded element of
think\paginator\Collection has no effect
这是因为$list不是一个数组,而是数据集对象think\Collection
下面是处理方法
// 查询状态为1的用户数据 并且每页显示10条数据
$list =
Db::name('user')->where('status',1)->paginate(10);
// 获取分页显示
$page = $list->render();
$data = $list->all();
foreach($data as
$key=>$val){
}
$this->assign('data',
$data);
$this->assign('page', $page);
// 渲染模板输出
return $this->fetch();
模板文件中分页输出代码如下:

加载中…