5 lines of a custom tag that save me tons of headache

Often times when I am writing ajax or model-glue apps, something will go wrong and its difficult to see the values that are complaining. Sure, you could pass things forward to the view, catch/try, maybe set your controller to allow output and dump it from there, but this little custom tag seems to do the trick most of the time for me.

<cfset dumpMe = attributes.var />
<cfsavecontent variable=<span class='cc_value'>"debug"</span>>
   <cfdump var=<span class='cc_value'>"#dumpMe#"</span>>
</cfsavecontent>
<cffile action=<span class='cc_value'>"write"</span> file=<span class='cc_value'>"#attributes.file#"</span> output=<span class='cc_value'>"#debug#"</span>>

its called 'fileDump.cfm' in my custom tags folder, and you use it just like you would think:

<cf_filedump var=<span class='cc_value'>"#varToDump#"</span> file=<span class='cc_value'>"c:\debug.html"</span> />

Now I will get a nice file I can open up regardless of the final rendered output of my page / event, and see what the heck is going on. You can dump the entire event, or the 'this' or 'variables' scope as well, and get the whole ball of wax in a nice file that you can dig through at your leisure!

Digg StumbleUpon Facebook Technorati Fav newsvine reddit FARK Google Bookmarks
  1. larry c. lyons

    #1 by larry c. lyons - July 25, 2008 at 2:47 PM

    Just a quick addition to your code, add the follow line before your cfdump:
    <cfset request.cfdumpinited = false />

    it will ensure that the formatting is correct.
  2. [Justice]

    #2 by [Justice] - July 27, 2008 at 6:39 PM

    Cool, I will update it ;) I also noticed that CF8 added a format="file" output="c:\full\filename.html" that makes this tag un-necessary. I will update the post!

Comments are closed.