Here is what I have done in the past:
In config/routes.phpadd the following:
Router::mapResources(array('restaurants', 'items'));
Router::parseExtensions('json');
In app/app_controller.php:
function beforeFilter() {
if ($this->isApiCall()) {
Configure::write('debug', 0);
}
}
function isApiCall() {
return $this->RequestHandler->isAjax()
|| $this->RequestHandler->isXml()
|| $this->RequestHandler->prefers('json');
}
app/views/items app/views/restaurants json . .json.
, app/views/layouts/json/default.ctp :
<?php echo $content_for_layout; ?>
, http://mydomain.com/items/view.json app/views/items/json/view.ctp, :
<?php echo $javascript->object($item); ?>
$item app/controllers/items_controller.php.
, , , JSON CakePHP.
UPDATE: .