收录日期:2020/07/07 02:04:54 时间:2013-03-08 14:39:34 标签:coldfusion,railo,cfml,openbd

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?

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.

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.

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>
<cffunction name="setAbort" access="private" returntype="void" output="false">
 <cfdump var="#arguments#"/><cfabort>
</cffunction>

Now plain tag names allowed within cfscript starting ColdFusion 11

<cfscript>
    cfdump (var=#myVar#);
</cfscript>

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
How to do a cfdump inside a cfscript tag? CFdump cfcomponent cfscript How to log information from inside how to set expiration date on a cookie in cfscript How do I vertically align something inside a span tag? Regular expression, how to find all tags A which do not contain tag IMG inside it? How do I add a pre tag inside a code tag with jQuery? How to position a span inside a headline tag? Is the CFDUMP tag modifiable? How to invoke a custom tag in servlet or inside another tag? How do I nest a div inside an anchor tag in rails How do I put an apostrophe inside of a DataBound server tag? Do I `HAVE` to add a space inside an empty DIV tag? How to programmatically create a