I'm generating a json from a find in CakePhp.
Controller:
public function listar() {
$this->layout = 'ajax';
$this->set('resultados', $this->Sala->listarSala());
}
Model:
public function listarSala() {
$options = array(
'fields' => array(
'Sala.id', 'Sala.nome', 'Sala.data', 'Sala.inicio', 'Sala.fim'
),
'conditions' => array(
'Sala.data >= curdate()',
),
'order' => array(
'Sala.data ASC',
'Sala.inicio ASC'
),
'limit' => 50
);
return $this->find('all', $options);
}
View:
<?php
echo json_encode($resultados);
But when I view the answer, I get the following result:
[
{"Sala":{"id":"47","nome":"Grupo","data":"15\/05\/2014","inicio":"09:30:00","fim":"11:00:00"}},
{"Sala":{"id":"48","nome":"Grupo","data":"29\/05\/2014","inicio":"09:30:00","fim":"11:00:00"}},
{"Sala":{"id":"49","nome":"Grupo","data":"12\/06\/2014","inicio":"09:30:00","fim":"11:00:00"}}
]
I noticed that it creates a room object (model) and within it the properties searched for in MySql.
My question is as follows, how could I make CakePhp return this result without the room object, with the normal jSon notation, or would it be anyway? What would be the correct way?