I am using cakephp 2.1 and I am a newbie. As Cakephp an ORM based, Can anyone tell me how would I get the data response in json? What steps I have to follow? please help!
Asked
Active
Viewed 141 times
1 Answers
1
This question has been answered countless times by now... A nice overall explanation can he found here.
There are two options in Cake:
Cake has JSON views that you can use to return data.
An empty layout and a view that returns JSON encoded data like:
echo json_encode($data)
Of course that data must be set prior in the Controller:
$dataFromDb = $this->Model->find('all');
$this->set('data', $dataFromDB);
And you also must set
Content-Type: application/json
as a header.

Community
- 1
- 1

Borislav Sabev
- 4,776
- 1
- 24
- 30