沃斯尼达耶
- 沃斯尼达耶 发表了说说大佬们 关注一下问题
- 沃斯尼达耶 回答了问题 AR 查询出来的 数据,怎么增加额外的属性。
用了这个方法
public function attributes () { $attributes = parent::attributes(); $attributes[] = 'count'; $attributes[] = 'name'; return $attributes; }
是多了两个属性 但是查询出来的结果 还是没有他俩, 是需要在哪里给这俩赋值么?
$attributes = Array ( [0] => id [1] => uid [2] => from_uid [3] => type [4] => amount [5] => ori_amount [6] => created_at [7] => totals [8] => is_incr [9] => remark [10] => sent [11] => sent_time [12] => count [13] => name )
// Yii2 active_record 添加额外属性 public function attributes() { $attributes = parent::attributes(); $attributes[] = 'type'; return $attributes; }
谢谢, 用了这个办法 还是没有
public function attributes () { $attributes = parent::attributes(); $attributes[] = 'count'; $attributes[] = 'name'; return $attributes; }
{"code":200,"error":0,"data":[{"id":"84","uid":325,"from_uid":327,"type":"rec","amount":"597.00","ori_amount":"1194.00","created_at":1553238260,"totals":"1791.00","is_incr":1,"remark":null,"sent":1,"sent_time":1553238260},{"id":"82","uid":325,"from_uid":327,"type":"rec","amount":"597.00","ori_amount":"597.00","created_at":1553238078,"totals":"1194.00","is_incr":1,"remark":null,"sent":1,"sent_time":1553238078},{"id":"80","uid":325,"from_uid":327,"type":"rec","amount":"597.00","ori_amount":"0.00","created_at":1553237952,"totals":"597.00","is_incr":1,"remark":null,"sent":1,"sent_time":1553237952}],"message":""}
- 沃斯尼达耶 回答了问题 AR 查询出来的 数据,怎么增加额外的属性。
在 AR 里使用
getXX
方法$model->xx
时才有值, 现在就是想查询出来的数据 能加入属性。 - 沃斯尼达耶 回答了问题 AR 查询出来的 数据,怎么增加额外的属性。
还有 比如数据表里是没有 count 属性的, 我怎么才能在每一条查询结果里 加上count属性 并且计算出结果赋值给count属性。
- 沃斯尼达耶 2019-04-09 已签到连续签到1天,获得了5个金钱
- 沃斯尼达耶 2019-04-04 已签到连续签到1天,获得了5个金钱
- 沃斯尼达耶 2019-03-26 已签到连续签到2天,获得了10个金钱