In order to debug I would like to dump certain variables on to my web page. How can I do that from inside a cfscript tag?
I tried the following but it isn't working:
<cfscript>
...
<cfif cgi.REMOTE_ADDR eq "IP">
<cfdump var="#var1#"><br/>
</cfif>
...
</cfscript>
Any clues on what can be done?
Use the cfdump tag to get the elements, variables, and values of most kinds of ColdFusion objects. Useful for debugging. You can display the contents of simple and complex variables, objects, components, user-defined functions, and other elements.
Outputs the contents of a variable of any type for debugging purposes. The variable can be as simple as a string or as complex as a cfc component instance.
You create most ColdFusion variables by assigning them values. (You must use the ArrayNew function to create arrays.) Most commonly, you create variables by using the cfset tag. You can also use the cfparam tag, and assignment statements in CFScript.
You can't do it directly like that in versions before CF 9. You can, however, use the dump() UDF found at CFLib. There's a whole library of UDFs there that mimic CF tags that don't have direct CFSCRIPT equivalents.
ColdFusion 9 (and up) offers the writeDump()
function.
Adobe Documentation Linkfor WriteDump() function
use writeDump() like how you use writeOutput()
see writeDump on CF 9 reference
Isn't the following much easier and straightforward?
oAdmin = createObject("component", "cfide.adminapi.base");
oAdmin.dump(myVar);
It works on CF7 and forward, perhaps even earlier.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With