29

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?

Jeromy French
  • 11,812
  • 19
  • 76
  • 129
Arnkrishn
  • 29,828
  • 40
  • 114
  • 128
  • Strongly related: http://stackoverflow.com/questions/1917706/cfdump-cfcomponent-cfscript/1917756 – ale Jun 21 '12 at 14:54

7 Answers7

43

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

Heemanshu Bhalla
  • 3,603
  • 1
  • 27
  • 53
ale
  • 6,369
  • 7
  • 55
  • 65
32

use writeDump() like how you use writeOutput()

see writeDump on CF 9 reference

Heemanshu Bhalla
  • 3,603
  • 1
  • 27
  • 53
Seeker
  • 1,250
  • 1
  • 16
  • 23
5

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.

3

Now plain tag names allowed within cfscript starting ColdFusion 11

<cfscript>
    cfdump (var=#myVar#);
</cfscript>
master-lame-master
  • 3,101
  • 2
  • 30
  • 47
3

It would be fairly easy to write your own too. You just define a function in cfml rather than cfscript. You can use this to do cfaborts and cfloops as well.

Something like this (Off the top of my head...not executed).

<CFFUNCTION NAME="MyDump">
    <CFARGUMENT NAME="OBJ" Required="TRUE">
    <CFDUMP VAR="#Obj#">
</CFFUNCTION>
<CFSCRIPT>
  if(cgi.REMOTE_ADDR eq "IP"){
    MyDump(Var1);
  }
</CFSCRIPT>
Tom Hubbard
  • 15,820
  • 14
  • 59
  • 86
2
<cffunction name="setAbort" access="private" returntype="void" output="false">
 <cfdump var="#arguments#"/><cfabort>
</cffunction>
dbinott
  • 911
  • 1
  • 11
  • 36
-1

For dump we use Writedump(myvar); instead of in cfscript and same we use abort; instead of for exit the execution of program at any instance.we use writeoutput(); instead of

 <cfoutput>#myvar#</cfoutput>

below is the code for dump and abort in cfscript.

writedump(myvar); for dump

abort; for stop execution of programm 

writeoutput(myvar); for output within cfscript
Rizwan Gill
  • 2,193
  • 1
  • 17
  • 29