美文网首页
thinkphp5报错 Call to a member fun

thinkphp5报错 Call to a member fun

作者: 小进我是爸爸 | 来源:发表于2019-08-20 16:41 被阅读0次

thinkphp5内报错Call to a member function toArray() on array

使用场景

        使用模型查询后,想获取不包含对象内容的数组结构的结果。

使用方式

$gardenAuth = new GardenAuth();

$res = $gardenAuth->where(['id'=>$id])->select()->toArray();

结果 

 Call to a member function toArray() on array

原因

数据库(database.php)里设置的返回数据结果为数组类型

'resultset_type' => 'array'

解决方式

方法一

    全局:改为 'resultset_type' => 'collection'

方法二:

     局部:在模型中加入

protected $resultSetType = 'collection';

相关文章

网友评论

      本文标题:thinkphp5报错 Call to a member fun

      本文链接:https://www.haomeiwen.com/subject/rugpsctx.html