I'm trying to return a Json object from an outside form with Cakephp 2.1. I have all my data, and I've looked at the responses, and the problem is I get a massive error text before my JSON!
Heres the code I use to print the json:
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 ;
}
The JSON it prints is correct, {"Email":["EmailUnique"]}
. However I get a huge preformatted error message before that, stack trace and everything.
It was a dumb moment, but the answer in case anyone else finds this:
Theres an error far earlier in the code, with debug on, cake will print it immediately. This will get wrapped into the json output.
The specific error turns out to not be relevant for this question, its just in the view.