0

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.

1
  • 3
    You expect us to guess the error, right? Commented Mar 10, 2017 at 16:23

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.