这是我的代码
$all = $this->find()
->select(['ProductCircles.id', 'ProductCircles.type', 'ProductCircles.name'])
->order(['ProductCircles.type'])
->all()
->toArray();
Log::write('error', $all);
$all = Hash::combine($all, '{n}.ProductCircles.id', '{n}.ProductCircles.name', '{n}.ProductCircles.type');
的$all
是ProductCircle实体的阵列。
但是,哈希组合无法像我期望的那样对数据起作用。
请指教。
$all
预期是ProductCircle实体的数组:
2015-03-15 08:04:36 Error: Array
(
[0] => App\Model\Entity\ProductCircle Object
(
[_accessible:protected] => Array
(
[name] => 1
[type] => 1
[product_count] => 1
[products_in_circles] => 1
)
[_properties:protected] => Array
(
[id] => 27
[type] => MATERIAL
[name] => Wood
)
[_original:protected] => Array
(
)
[_hidden:protected] => Array
(
)
[_virtual:protected] => Array
(
)
[_className:protected] => App\Model\Entity\ProductCircle
[_dirty:protected] => Array
(
)
[_new:protected] =>
[_errors:protected] => Array
(
)
[_registryAlias:protected] => ProductCircles
)
这是我所期望的。
我想对Hash :: combine进行的操作是获得像这样的数组数组:
$result:
[
[MATERIAL] => [
[27] => [
Wood
]
]
不要使用哈希,而是使用查询对象中内置的收集方法:
$combined = $this->find()
->select(['ProductCircles.id', 'ProductCircles.type', 'ProductCircles.name'])
->order(['ProductCircles.type'])
->combine('id', 'name', 'type')
->toArray();
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句