tp 5.1 使用模型查询结果集插入另一个模型的问题

问题场景:使用模型查询了某条数据返回,并将结果集使用模型插入到另一张表,插入后有返回但是没有插入成功。

如:

TemplateModel::create($res, true);

原因:模型无论使用get还是find方法查询,返回的是都当前模型的对象实例,返回的是对象不是数组

解决办法:

将返回的结果集转化为数组

 $res = json_decode(json_encode($res), true);
 $template = TemplateModel::create($res, true);

猜你喜欢

转载自www.cnblogs.com/makalochen/p/13204473.html