I am converting the returning value of CakePHP array to JSON, currently its like this:
{
"platformusers" : [
{
"id" : "1",
"name" : "user1"
},
{
"id" : "3",
"name" : "user3"
}
]
}
And I want it to be like this:
[
{
"id" : "1",
"name" : "user1"
},
{
"id" : "3",
"name" : "user3"
}
]
I am trying with Set::extract('{n}.Model', $data) Hash::extract('{n}.Model', $data) with no luck at all.
Full code:
$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')
));
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…