【发布时间】:2021-08-03 07:54:55
【问题描述】:
我有两个对象 coins 和 user_summarry
$coins = $this->coins->find('all')
$user_summarry = $this->UserSummary->find('all')
如果我使用toArray() 来表示硬币,它看起来像
[
(int) 0 => object(App\Model\Entity\Coin) id:0 {
'id' => (int) 1
'name' => 'A'
}
(int) 1 => object(App\Model\Entity\Coin) id:0 {
'id' => (int) 2
'name' => 'B'
}
....
]
toArray() 为user_summarry
[
(int) 0 => object(App\Model\Entity\UserSummary) id:0 {
'id' => (int) 1
'coin_id' => '2'
'total' => 120
}
...
]
我怎样才能改变我的硬币对象像
(int) 0 => object(App\Model\Entity\Coin) id:0 {
'id' => (int) 1
'name' => 'A',
'total' => 0
}
(int) 1 => object(App\Model\Entity\Coin) id:0 {
'id' => (int) 2
'name' => 'B',
'total' => 120
}
使用 2 个 foreach 循环更改数组后,我可以将其更改为数组。如何使用 cakephp 方法映射和连接为对象?
【问题讨论】:
标签: cakephp cakephp-4.x