Cakephp How to query the paid amount?

寵の児 提交于 2020-05-09 17:01:12

问题


I dont know whats wrong but my code dont output the paid amount column

$payment_tbl = TableRegistry::get("MembershipPayment");
$payments = $payment_tbl->find();
$payments->select(['payment_total'=> $payments->func()->sum('paid_amount')]);
$this->set("payments",$payments);

and then echo this as echo $payments->payment_total;


回答1:


$payments will be a query result object, not a single result. With this query, where you're expecting just a single row, add ->first() after your sum call.

In general, if you're not getting what you expect, dump the contents of the variable in question, like with pr($payments) or debug($payments), that will very often very quickly give you a clear indication of what the problem is. In this case, you'll see it's not the Entity object that you're expecting.



来源:https://stackoverflow.com/questions/61278984/cakephp-how-to-query-the-paid-amount

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!