【发布时间】:2014-03-17 20:56:43
【问题描述】:
在 CakePhp 项目中,我有一个带有控制器的项目模型:
class ItemsController extends AppController{
public $components = array('RequestHandler');
public function data(){
$items = $this->Item->find('all');
$this->set('items', $items);
$this->set('_serialize', array('items'));
}
}
通过在routes.php 中指定:
Router::parseExtensions('json');
向/items/data.json 发出请求时,我得到了我想要的 JSON 响应
调用 /items/data 时如何获得 JSON 响应?以及如何在路由中连接 JSON 响应。例如,如果我希望 /data/items.php 呈现与 /items/data.json 请求相同的 JSON。
谢谢!
【问题讨论】:
标签: php json cakephp cakephp-2.4