【发布时间】:2013-03-02 19:12:43
【问题描述】:
所以我正在尝试创建一个 Android 移动应用程序,并且我使用 CakePHP 作为我的服务器端。我不需要任何 HTML 视图,我只会使用 JSON 对象进行响应。
我查看了http://book.cakephp.org/2.0/en/core-libraries/components/request-handling.html#RequestHandlerComponent 并创建了这个:
class LocationsController extends AppController
{
public $helpers = array('Html', 'Form');
public $components = array('RequestHandler');
function index()
{
$locations = $this->Location->getNearest();
$this->set(compact('locations'));
$this->set('_serialize', array('locations'));
}
}
我已将此添加到我的routes.php:
Router::mapResources('locations');
Router::parseExtensions('json');
当我运行它时,除了默认的 CakePHP 布局样式外,什么都没有显示。如果我删除 index.ctp 视图文件,我会收到一个错误,即找不到视图文件。为什么它仍然需要视图文件?我认为使用序列化方法不需要视图。我尝试查看 Google Chrome 开发者控制台,但没有包含 JSON 对象的响应。但是,MySQL 的表现非常好。
【问题讨论】:
标签: json debugging cakephp dataview requesthandler