I am not sure if this is the fanciest way to get the job done but it works REALLY well. What job am I referring to? I am referring to outputting data as JSON in a CakePHP view and then parsing it in a jQuery AJAX response. Its fairly easy to accomplish with the JSON parser provided by json.org. Scroll to the bottom and download/include json2.js.
Controller example:
$sizeArray = getimagesize('/path/to/really_cool_image.jpg');
$outputArray = array(
'file' => 'really_cool_image.jpg',
'width' => $sizeArray[0],
'height' => $sizeArray[1],
);
$this->set('result', $outputArray);
$this->render(null, 'ajax');
AJAX View example:
Configure::write('debug', 0);
echo $javascript->object($result);
jQuery AJAX response handler example:
function(response, status) {
imageDetails = JSON.parse(response);
imageName = imageDetails.file;
}
