m0_37683990
2022-02-17 18:32
采纳率: 0%
浏览 39

PHP的 Laravel 框架和TP5,为什么要把结果转对象来处理呢??

例如,我用框架的Model执行了一下mysql 数据库查询之后,返回结果为:


Array
(
    [0] => app\common\model\walmart\WalmartListing Object
        (
            [query:protected] => erp\ErpQuery
            [virtualFields:protected] => Array
                (
                )

            [connection:protected] => Array
                (
                )

            [name:protected] => WalmartListing
            [table:protected] => 
            [class:protected] => app\common\model\walmart\WalmartListing
            [error:protected] => 
            [validate:protected] => 
            [pk:protected] => 
            [field:protected] => Array
                (
                )

            [readonly:protected] => Array
                (
                )

            [visible:protected] => Array
                (
                )

            [hidden:protected] => Array
                (
                )

            [append:protected] => Array
                (
                )

            [data:protected] => Array
                (
                    [id] => 11
                    [account_id] => 37
                    [vid] => 15
                    [sku_id] => 100529
                    [variation_sku] => LA0Q3C9FBN99MF2601
                    [price] => 23121.00
                    [inventory] => 5
                )

            [change:protected] => Array
                (
                )

            [auto:protected] => Array
                (
                )

            [insert:protected] => Array
                (
                )

            [update:protected] => Array
                (
                )

            [autoWriteTimestamp:protected] => 
            [createTime:protected] => create_time
            [updateTime:protected] => update_time
            [dateFormat:protected] => 
            [type:protected] => Array
                (
                )

            [isUpdate:protected] => 1
            [updateWhere:protected] => 
            [relation:protected] => 
            [failException:protected] => 
            [useGlobalScope:protected] => 1
            [batchValidate:protected] => 
            [resultSetType:protected] => array
            [relationWrite:protected] => 
            [filterClass:protected] => 
        )

)

为什么不是返回简简单单的数组呢?用惯了旧框架,和原生,早就习惯了用数组处理。

这个把结果转成对象的形式返回,有什么好处吗?目的是啥?

求详细解答下,谢谢啦

2条回答 默认 最新

相关推荐 更多相似问题