我正在将 CakePHP 数组的返回值转换为 JSON,目前是这样的:
{
"platformusers" : [
{
"id" : "1",
"name" : "user1"
},
{
"id" : "3",
"name" : "user3"
}
]
}
我希望它是这样的:
[
{
"id" : "1",
"name" : "user1"
},
{
"id" : "3",
"name" : "user3"
}
]
我正在尝试Set::extract('{n}.Model', $data)Hash::extract('{n}.Model', $data) 一点运气都没有。
完整代码:
$platformusers = $this->Platformuser->find('all', array(
'fields' => array('Platformuser.id', 'Platformuser.name')
));
$platformusers = Hash::extract('{n}.Platformuser', $platformusers);
$this->set(array(
'platformusers' => $platformusers,
'_serialize' => array('platformusers')
));