Cakephp如何查询支付金额? [英] Cakephp How to query the paid amount?
问题描述
我不知道出了什么问题,但是我的代码没有输出支付金额列
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);
然后将其作为echo $ payments-> payment_total;
and then echo this as echo $payments->payment_total;
推荐答案
$ payments
将成为查询结果对象,而不是单个结果。通过此查询,您只希望在一行中添加-> first()
在您的 sum
之后
$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.
通常,如果您没有得到期望的结果,请转储相关变量的内容,例如使用 pr($付款)
或 debug($ payments)
,通常会很快非常清楚地指出问题所在。在这种情况下,您会看到它不是您期望的Entity对象。
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.
这篇关于Cakephp如何查询支付金额?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!