Raymond Camden's Blog Rss

Per request debugging in Model-Glue

7

Posted in ColdFusion | Posted on 09-18-2006 | 4,229 views

A few weeks ago I spoke about how I use AJAX with Model-Glue. A reader, Jan Jannek, asked how she could use debugging without it breaking the XML results being returned by Model-Glue. Before I even had a chance to find the answer, she was able to dig it up:

I just found out by having a look at the MG-Examples of ajaxCFC, that there is the option to get rid of the debugging for a single event by adding:

<cfset request.modelGlueSuppressDebugging = true />

to the xml.view.cfm and everything works fine!

I confirmed this and it worked well. However - a note. Let's say you want to turn on debugging, but hide it by default. If you pass in a URL variable you would then want the debugging information to show up. This would be a bad idea for production, but during testing it would let you quickly see debugging information on a per request basis. This is possible, but you should be aware that Model-Glue does not actually check the value of request.modelGlueSupressDebugging. The mere existence of the variable will turn of debugging. Here is a simple way to add this functionality:

view plain print about
1<cfset request.modelGlueSuppressDebugging = true />
2<cfif structKeyExists(url, "showdebug")>
3    <cfset structDelete(request, "modelGlueSuppressDebugging")>
4</cfif>

This code simply looks for "showdebug" in the query string and if it exists, it removes the request variable instead of simply setting it to false. (This should be added to your application.cfm file of course.)

Comments

[Add Comment] [Subscribe to Comments]

Although I haven't done any testing with AJAX-specific code, I have found that any JavaScript will break in Model Glue if you have debugging (and "Report Execution Times ") turned on. Turn off Report Execution Times and things start working.

One of the internal Model Glue methods (ViewRender?) will show up in the template list, thus duplicating the contents of the view on the page. How does JavaScript know which named element you are accessing when it exists twice? It doesn't.

This is one of the issue I cover in an upcoming article for FAQU.
I should have been clear that I was speaking of MG debugging, not CF debugging. But you can turn off CF debugging on a per request basis as well.
It may help if I mention the actual code in case folks don't know. To turn off debugging in CF on a request basis, use:

&lt;cfsetting showDebugOutput="false"&gt;
I'm a victim of not reading too closely. ;)
No - your point is definitely valid and would also screw up AJAX calls, so thanks for bringing it up. :)
Ray, it is very important to note that turning off debugging per request like you mention does not remove or even reduce the performance hit you take with things like Model-Glue, Reactor or other frameworks. The debugging still runs as usual, only the output is suppressed.
I did say you should not do this in production, but I didn't make it clear why. Thanks Brian.

[Add Comment] [Subscribe to Comments]