TP5报如下的错误 Indirect modification of overloaded element of thinkpaginatorCollection has no effect(代码片段

Posted killbugme

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了TP5报如下的错误 Indirect modification of overloaded element of thinkpaginatorCollection has no effect(代码片段相关的知识,希望对你有一定的参考价值。

控制器中关键代码如下:

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

模板文件中分页输出代码如下:

<div>
<ul>
{volist name=‘list‘ id=‘user‘}
       <li> {$user.nickname}</li>
{/volist}
</ul>
</div>
{$list->render()}

上面的方法非常简单,但是如果我想在查询出来的数据中加入新的值的,上面的方法就不能用了,当你尝试对$list进行循环的时候,会报如下的错误

Indirect modification of overloaded element of thinkpaginatorCollection has no effect

这是因为$list不是一个数组,而是数据集对象thinkCollection

下面是处理方法

// 查询状态为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();

模板文件中分页输出代码如下:

<div>
    <ul>
        {volist name=‘data‘ id=‘user‘}
        <li>{$user.nickname}</li>
        {volist}
    </ul>
</div> 

原文链接:http://blog.sina.com.cn/s/blog_4cd978f90102yelk.html

以上是关于TP5报如下的错误 Indirect modification of overloaded element of thinkpaginatorCollection has no effect(代码片段的主要内容,如果未能解决你的问题,请参考以下文章

tp5.1路由报错No input file specified.

TP5通过model更新mysql数据表字段值为汉字时,总是报字符转义的错,字母和数字可以;

TP5动态路由配置好了但是报错was not found on this server的原因以及解决方法

关于excel 的indirect函数 里面带函数错误?

delete() destroy()删除数据的区别---ThinkPHP5(TP5)对数据库操作总结

excel中INDIRECT公式写的没错,怎么提示错误啊