CakePHP3集合每个迭代器不修改项
我正在尝试向集合中的每个项添加“modelType”属性。然而,它似乎并没有在之后出现:CakePHP3集合每个迭代器不修改项,cakephp,collections,cakephp-3.x,Cakephp,Collections,Cakephp 3.x,我正在尝试向集合中的每个项添加“modelType”属性。然而,它似乎并没有在之后出现: $results->each(function($row, $index) use ($modelType) { $row['modelType'] = $modelType; }); debug($results->toArray()); //<---- modelType isn't listed in any of my items $results->each(函数($r
$results->each(function($row, $index) use ($modelType) {
$row['modelType'] = $modelType;
});
debug($results->toArray()); //<---- modelType isn't listed in any of my items
$results->each(函数($row,$index)使用($modelType){
$row['modelType']=$modelType;
});
调试($results->toArray())// 我明白了。
在我的示例代码中,$results是由设置为false的查询生成的,该查询返回数组而不是实体
取出->水合物(false),然后每个循环按预期修改集合。解决了这个问题。
在我的示例代码中,$results是由设置为false的查询生成的,该查询返回数组而不是实体
取出->水合物(false),然后每个循环按预期修改集合