用Cakephp呈现JSON
我试图使用Cakephp 2.1从外部表单返回Json对象。我有我所有的数据,我已经查看了回复,问题是我在JSON之前收到了大量的错误文本 下面是我用来打印json的代码:用Cakephp呈现JSON,php,json,cakephp,Php,Json,Cakephp,我试图使用Cakephp 2.1从外部表单返回Json对象。我有我所有的数据,我已经查看了回复,问题是我在JSON之前收到了大量的错误文本 下面是我用来打印json的代码: if (!$validationPassed) { if ($ExternalRequest) { if ($shouldEchoErrors){ Configure::write('debug',0); // Disabled so theoretically it c
if (!$validationPassed) {
if ($ExternalRequest) {
if ($shouldEchoErrors){
Configure::write('debug',0); // Disabled so theoretically it can't even print errors
$this->RequestHandler->setContent('json', 'application/json' );
$json = json_encode($this->Customer->validationErrors);
echo $json;
$this->autoRender = false ;
}
它打印的JSON是正确的,{Email:[EmailUnique]}。然而,在此之前,我得到了一个巨大的预格式化错误消息,堆栈跟踪和所有内容 这是一个愚蠢的时刻,但如果其他人发现这个问题,答案是: 在代码的前面有一个错误,当debug打开时,cake将立即打印它。这将被包装到json输出中
具体的错误与这个问题无关,它只是在视图中 你希望我们猜出错误,对吗?