We know that there is a layout for XML and AJAX response in CakePHP that did their job well. But what can we do to get an easy JSON response from a controller action?
It is easier then i thought, with the new CakeResponse.
Create an array that you want to convert into a JSON string in your controller action and just one line of code generates your response:
return new CakeResponse(array('body' => json_encode($array)));
No $this->set() or echo $string is needed anymore.
I use this to answer requests from an Android App and it works nice and fast. 🙂