【发布时间】:2017-12-07 19:17:18
【问题描述】:
我想显示特定日期最后插入行的字段 (bal)。
$BALdata171201 = ORM::for_table('sys_transactions')->where('date',$data171201)->select('bal')->order_by_desc('id')->limit(1)
但我不断收到错误:
可捕获的致命错误:ORM 类的对象无法转换为字符串
如何在字符串中进行 ORM 对象转换?
我已经阅读了几十个关于这个问题的答案,但我没有找到任何解决方案。
如果我使用 var_dump 我会得到:
object(IdiormResultSet)#132 (1) {
["_results":protected]=>
array(1) {
[0]=>
object(ORM)#131 (22) {
["_connection_name":protected]=>
string(7) "default"
["_table_name":protected]=>
string(16) "sys_transactions"
["_table_alias":protected]=>
NULL
["_values":protected]=>
array(0) {
}
["_result_columns":protected]=>
array(1) {
[0]=>
string(1) "*"
}
["_using_default_result_columns":protected]=>
bool(true)
["_join_sources":protected]=>
array(0) {
}
["_distinct":protected]=>
bool(false)
["_is_raw_query":protected]=>
bool(false)
["_raw_query":protected]=>
string(0) ""
["_raw_parameters":protected]=>
array(0) {
}
["_where_conditions":protected]=>
array(0) {
}
["_limit":protected]=>
NULL
["_offset":protected]=>
NULL
["_order_by":protected]=>
array(0) {
}
["_group_by":protected]=>
array(0) {
}
["_having_conditions":protected]=>
array(0) {
}
["_data":protected]=>
array(1) {
["bal"]=>
string(7) "1354.00"
}
["_dirty_fields":protected]=>
array(0) {
}
["_expr_fields":protected]=>
array(0) {
}
["_is_new":protected]=>
bool(false)
["_instance_id_column":protected]=>
NULL
}
}
}
我已经尝试过 $BALdata171201string = $BALdata171201string->_data; 但我得到了一个空的回声。
【问题讨论】:
-
这是一个ORM,你试过
$BALdata171201string->bal吗? -
这是一些疯狂的变量命名约定。
-
哈哈我把这个名字取了,因为我需要使用excel来为一年中的每一天生成这行代码。
-
我试过你伤心的。现在我已经解决了我的问题。在前端我使用: {$BALdata171201} 现在我正在使用: {foreach $BALdata171201 as $b01s} {if {$b01s['bal']} ge 0 }Balanço br>R$ {$b01s['bal']}{/foreach}{/if} 像魅力一样工作。非常感谢你的回复! ;D
标签: php mysql object orm idiorm