How to do a cfdump inside a cfscript tag?

前端 未结 7 1740
滥情空心
滥情空心 2021-01-17 07:24

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

相关标签:
7条回答
  • 2021-01-17 07:56

    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.

    0 讨论(0)
  • 2021-01-17 07:59

    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

    0 讨论(0)
  • 2021-01-17 07:59

    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>
    
    0 讨论(0)
  • 2021-01-17 07:59

    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
    
    0 讨论(0)
  • 2021-01-17 08:08

    Now plain tag names allowed within cfscript starting ColdFusion 11

    <cfscript>
        cfdump (var=#myVar#);
    </cfscript>
    
    0 讨论(0)
  • 2021-01-17 08:11
    <cffunction name="setAbort" access="private" returntype="void" output="false">
     <cfdump var="#arguments#"/><cfabort>
    </cffunction>
    
    0 讨论(0)
提交回复
热议问题