如何重命名cakephp中的json键?

时间:2017-11-14 06:36:32

标签: arrays json cakephp cakephp-3.0

我有一个JSON对象,其中包含以下内容:

[{"price_id":1501822498,"name":"abc"},
{"price_id":1501825921,"name":"xyz"}]

我想更改" price_id"关键是" id"所以它会成为

[{"id":1501822498,"name":"abc"},
{"id":1501825921,"name":"xyz"}]

我怎样才能在cakephp中做到这一点?

我的cakephp json代码是

$searchitem = $this->MbPriceList->find('all' , [
 'fields' => [ 
  'price_id',
            'name' => 't1.item_name'
        ], 
        'join' => [
            'table' => 'mb_item_list', 
            'alias' => 't1', 
            'type' => 'INNER', 
            'conditions' => [
            't1.item_code = MbPriceList.item_code'
            ]
        ]
    ]) ->toArray();

0 个答案:

没有答案