关于如何将all()求出的对象转换为数组 [ 2.0 版本 ]
使用$this->find()->with('category')->all();
求出的数据中包括category数据,这个数据是一个对象,当使用return的时候 category数据就消失了
求问如何让category显示出来
[0] => apiend\models\Document Object
(
[_attributes:yii\db\BaseActiveRecord:private] => Array
(
[id] => 1
[uid] => 1
[name] =>
[title] => 新技能get√ QQ红包恶搞与测试:一个没有口令的口令红包
[category_id] => 41
[description] => 今天老D来给大家分享一个QQ红包恶搞手法,给QQ群里或者好友发一个没有口令的口令红包,但是他们却领取不了。一般QQ口令红包你点击红包它会自动在信息输入框输入口令,但是这个我们把口令弄成“空白”,然后他们就只能眼巴巴的看着红包了,然后你成功拉取仇恨了~~~
[root] => 0
[pid] => 0
[model_id] => 0
[type] => 0
[position] => 1
[link_id] => 0
[cover_id] => 15
[display] => 10
[deadline] => 0
[attach] => 0
[view] => 0
[comment] => 0
[extend] => 0
[level] => 0
[create_time] => 1482384769
[update_time] => 1482384769
[status] => 10
)
[_oldAttributes:yii\db\BaseActiveRecord:private] => Array
(
[id] => 1
[uid] => 1
[name] =>
[title] => 新技能get√ QQ红包恶搞与测试:一个没有口令的口令红包
[category_id] => 41
[description] => 今天老D来给大家分享一个QQ红包恶搞手法,给QQ群里或者好友发一个没有口令的口令红包,但是他们却领取不了。一般QQ口令红包你点击红包它会自动在信息输入框输入口令,但是这个我们把口令弄成“空白”,然后他们就只能眼巴巴的看着红包了,然后你成功拉取仇恨了~~~
[root] => 0
[pid] => 0
[model_id] => 0
[type] => 0
[position] => 1
[link_id] => 0
[cover_id] => 15
[display] => 10
[deadline] => 0
[attach] => 0
[view] => 0
[comment] => 0
[extend] => 0
[level] => 0
[create_time] => 1482384769
[update_time] => 1482384769
[status] => 10
)
[_related:yii\db\BaseActiveRecord:private] => Array
(
[category] => apiend\models\Category Object
(
[_attributes:yii\db\BaseActiveRecord:private] => Array
(
[id] => 41
[name] => black
[title] => 黑科技
[pid] => 0
[sort] => 0
[list_row] => 10
[meta_title] =>
[keywords] =>
[description] =>
[model] =>
[type] =>
[link_id] => 0
[allow_publish] => 0
[display] => 0
[reply] => 0
[check] => 0
[reply_model] =>
[extend] => 傻子
[create_time] => 1482384472
[update_time] => 1482384472
[status] => 0
[icon] => 0
)
[_oldAttributes:yii\db\BaseActiveRecord:private] => Array
(
[id] => 41
[name] => black
[title] => 黑科技
[pid] => 0
[sort] => 0
[list_row] => 10
[meta_title] =>
[keywords] =>
[description] =>
[model] =>
[type] =>
[link_id] => 0
[allow_publish] => 0
[display] => 0
[reply] => 0
[check] => 0
[reply_model] =>
[extend] => 傻子
[create_time] => 1482384472
[update_time] => 1482384472
[status] => 0
[icon] => 0
)
[_related:yii\db\BaseActiveRecord:private] => Array
(
)
[_errors:yii\base\Model:private] =>
[_validators:yii\base\Model:private] =>
[_scenario:yii\base\Model:private] => default
[_events:yii\base\Component:private] => Array
(
)
[_behaviors:yii\base\Component:private] => Array
(
)
)
)
[_errors:yii\base\Model:private] =>
[_validators:yii\base\Model:private] =>
[_scenario:yii\base\Model:private] => default
[_events:yii\base\Component:private] => Array
(
)
[_behaviors:yii\base\Component:private] => Array
(
)
)
[
{
"id": "2",
"uid": "1",
"title": "test",
"category_id": "41",
"description": "test",
"root": "0",
"pid": "0",
"model_id": 0,
"type": 0,
"position": 1,
"link_id": "0",
"cover_id": "16",
"display": 10,
"deadline": "0",
"attach": 0,
"view": "0",
"comment": "0",
"extend": "0",
"level": 0,
"create_time": "1482385024",
"update_time": "1482385024",
"status": 10
}
],
dashixiong 补充于 2016-12-26 15:30
使用了restful配置
dashixiong 补充于 2016-12-26 15:34
使用ActiveDataProvider类倒是可以返回category数据,但是不是很灵活,尤其是那个分页,例如假设我想取从第二条数据开始取3条传参数就不是那么方便了。
最佳答案
-
Modlename::find()->where([])->asarray()->all();
共 2 条回复dashixiong 回复于 2016-12-29 15:51 回复神回答,果然高人还是在这里
@dashixiong 这样不是原生的数组
三亩地 , dashixiong 觉得很赞
其他 5 个回答
dashixiong 北京
注册时间:2015-12-31
最后登录:2021-06-08
在线时长:53小时27分
最后登录:2021-06-08
在线时长:53小时27分
- 粉丝12
- 金钱3253
- 威望150
- 积分5283