I use cakephp 3. Here I need the summation of the field, I already did it.
$user_balance = $this->Users->find();
$user_balance
->select(['sum' => $user_balance->func()->sum('Users.balance')])
->first();
foreach ($user_balance as $balance) {
$this->set("user_balance", $balance->sum);
}
Here I used first (), but why does it still return an object. Is it possible to get a direct sum or an array. Here I do not want to use foreach.
source
share