How to do a cfdump inside a cfscript tag?

2019-02-21 09:15发布

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?

7条回答
霸刀☆藐视天下
2楼-- · 2019-02-21 09:55

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.

查看更多
可以哭但决不认输i
3楼-- · 2019-02-21 09:56
<cffunction name="setAbort" access="private" returntype="void" output="false">
 <cfdump var="#arguments#"/><cfabort>
</cffunction>
查看更多
Summer. ? 凉城
4楼-- · 2019-02-21 10:00

Now plain tag names allowed within cfscript starting ColdFusion 11

<cfscript>
    cfdump (var=#myVar#);
</cfscript>
查看更多
劳资没心,怎么记你
5楼-- · 2019-02-21 10:07

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

查看更多
何必那么认真
6楼-- · 2019-02-21 10:10

use writeDump() like how you use writeOutput()

see writeDump on CF 9 reference

查看更多
Bombasti
7楼-- · 2019-02-21 10:20

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
查看更多
登录 后发表回答