谁一开始就是大神?

关于如何将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红包恶搞手法,给Q 里或者好友发一个没有口令的口令红包,但是他们却领取不了。一般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红包恶搞手法,给Q 里或者好友发一个没有口令的口令红包,但是他们却领取不了。一般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
            }
        ],

Modlename::find()->where([])->asarray()->all();
asArray()->all()
->toArray()
asArray()
取数据是 加上 ->asArray();
https://jingyan.baidu.com/article/75ab0bcb98991dd6864db2aa.html

赞(0) 打赏
未经允许不得转载:菜鸟之家 » 关于如何将all()求出的对象转换为数组[2.0]

评论 抢沙发

登录

找回密码

注册