Debug is breaking my JSON... How to disable it from some methods ? |
Hi everyone !
The debug is breaking my JSON return.... Since my app is heavily based on JSON returns, I decided to keep it in a view file. The problem is that CI is adding a html comment on it ! PHP Code: public function jsonFormAdd() The json: Code: <!-- DEBUG-VIEW START 1 APPPATH/Config/../Views/ExpAdmin/ExpData/Candidates/Json/formAdd.php --> How to disable the toolbar there ? Thank you !
Interesting. That's being added by the debug toolbar. I think you can do 1 of 2 things:
1) Edit app/Config/Toolbar.php and comment out the views collector on line 23 2) You could edit app/Config/Filters.php and change how the toolbar is called. Currently it's a global setting. You could change that to ignore all routes starting in api/* for example.
I tried to do that... as stated in the userguide....
But it didn't work... I had to change the CI_DEBUG variable in Boot/development.php PHP Code: <?php namespace Config; PHP Code: /*
Did you try the other method I mentioned and comment out the view collector in the Toolbar config file? Pretty sure the View lib checks for the existence of that to determine whether to wrap the view in those comments or not.
That worked as well...
Thank you! I will turn it back on when I need debug... BTW, the debug toolbar is AWESOME !
Glad you like it! Still more I'd like to do with it, but it makes a great start already.
(10-07-2019, 08:11 PM)kilishan Wrote: Glad you like it! Still more I'd like to do with it, but it makes a great start already. LOVE IT ! Just one more quick question... Do you think that it is a good practice to store and generate the JSON in the view ? My app doesnt return any HTML, just json. And using a template engine I render the HTML in the frontend.
I typically delegate views to just HTML. I suppose if it works well for you then great. Seems like it might be challenging to get the JSON returned well. I'd probably just build the array of data to return as JSON in the controller, or another library more likely, then use $this->response->setJSON() to return it. You might also look at the API Response Trait to help with responses.
For others looking for solution, just define MIME/"Content-Type" for proper response with all content types if similar functions to "setJSON" doesn't exist.
CodeIgniter automatically disables debug bar in dev when you need to output something other than HTML. PHP Code: public function MyResponse(){
I know this is old now, but I had a similar problem when creating a CSV output.
I used this code within the controller to remove the DEBUG comment lines: Code: $response = view("export/csv", $data); |
Welcome Guest, Not a member yet? Register Sign In |