加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

TP5报错Indirectmodificationofoverloadedelementofthink\paginator\Collectionhasnoeffect

(2018-12-09 11:38:05)
标签:

thinkphp

tp5

分类: 语言程序
TP5报如下的错误 Indirect modification of overloaded element of think\paginator\Collection has no effect

控制器中关键代码如下:

// 查询状态为1的用户数据 并且每页显示10条数据
$list = Db::name('user')->where('status',1)->paginate(10);
// 把分页数据赋值给模板变量list
$this->assign('list', $list);
// 渲染模板输出
return $this->fetch();
模板文件中分页输出代码如下:

TP5报错Indirectmodificationofoverloadedelementofthink\paginator\Collectionhasnoeffect

上面的方法非常简单,但是如果我想在查询出来的数据中加入新的值的,上面的方法就不能用了,当你尝试对$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){
    $data[$key]['key'] = $key;
}
$this->assign('data', $data);
$this->assign('page', $page);
// 渲染模板输出
return $this->fetch();
模板文件中分页输出代码如下:

TP5报错Indirectmodificationofoverloadedelementofthink\paginator\Collectionhasnoeffect

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有