Take the 2-minute tour ×
Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. It's 100% free, no registration required.

While developing an API for a client site I recognized that there was a tag being returned after our JSON response (generated using BaseController's returnJson method).

I copy & pasted some of the output into The Google and found a reference to the YII_DEBUG constant. I checked the value (true) and assumed it was related to devMode. I turned off devMode for this environment and the extra code went away (and YII_DEBUG===false).

I don't suspect that this extra output is expected while using the returnJson() method but I need to get around this. Can I turn off devMode outside of the config file? I really only want to make an exception when calling this method.

share|improve this question
    
The question has been answered but I'd love to hear from P&T on whether or not this may change in a future release –  Tyler Willingham Jul 11 at 2:35
    
What exactly is the extra output? Is it a bunch of console.log() calls (the profiler info)? –  Brandon Kelly Jul 11 at 3:07
    
Yup, that's correct. There are a bunch of console.log calls –  Tyler Willingham Jul 11 at 9:17
    
Got it. Right now Craft will only hide those if it’s an Ajax request. Would make sense that it’s based on the MIME type instead, though. –  Brandon Kelly Jul 11 at 16:17
    
I agree. I can't think of a situation where I would actually want that output in my JSON file :) –  Tyler Willingham Jul 11 at 16:38

2 Answers 2

up vote 4 down vote accepted

I had the same problem. See Brad's response here to so this without messing with devMode: Console script tags garbling up non-html output (e.g. json) when in devMode

It would be nice if this happened automatically when specifically outputting non-html, though.

share|improve this answer

You can turn off dev mode for just this page/call if you'd like, using the config->set API method.

craft()->config->set('devMode', false);

Don't forget to turn it back on after your function runs (if it still matters at that point).

share|improve this answer
    
Thank you! I'm setting devMode=false right before calling the BaseController::returnJson method. This is okay because the returnJson method spins down craft with craft->end() after echo'ing the json encoded data. –  Tyler Willingham Jul 11 at 2:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.