沃斯尼达耶
- 沃斯尼达耶 提出了问题记录日志,限制日志个数无效
- 沃斯尼达耶 2019-04-17 已签到连续签到3天,获得了15个金钱
- 沃斯尼达耶 发表了说说文明上网,理性发言
- 沃斯尼达耶 2019-04-16 已签到连续签到2天,获得了10个金钱
- 沃斯尼达耶 2019-04-15 已签到连续签到1天,获得了5个金钱
- 沃斯尼达耶 2019-04-12 已签到连续签到2天,获得了10个金钱
- 沃斯尼达耶 回答了问题 AR 查询出来的 数据,怎么增加额外的属性。
这两个方法都能实现 但是就这个问题来说 感觉2 反倒是麻烦了呢。
1.
$list = User::find()->where(['status' => 0])->all();
foreach ($list as &$v) {$v->type = 1;
}
var_dump($list);exit;
2.
$query = Industry::find()->select(['id', 'name', 'description', 'sort', 'updated_at'])->where(['status' => Industry::STATUS_ACTIVE]) ->orderBy(['sort' => SORT_DESC, 'id' => SORT_ASC]);
$industries = ArrayHelper::toArray($query->all(), [Industry::class => [
'id', 'name', 'description', 'sort', 'updated_date' => function($model){ return Helper::formatTime($model->updated_at); },
]]);
- 沃斯尼达耶 赞了回答
用
ArrayHelper::toArray()
方法$query = Industry::find()->select(['id', 'name', 'description', 'sort', 'updated_at']) ->where(['status' => Industry::STATUS_ACTIVE]) ->orderBy(['sort' => SORT_DESC, 'id' => SORT_ASC]); $industries = ArrayHelper::toArray($query->all(), [Industry::class => [ 'id', 'name', 'description', 'sort', 'updated_date' => function($model){ return Helper::formatTime($model->updated_at); }, ]]);
- 沃斯尼达耶 2019-04-11 已签到连续签到1天,获得了5个金钱