Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do a cfdump inside a cfscript tag?

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?

like image 527
Arnkrishn Avatar asked May 19 '09 15:05

Arnkrishn


People also ask

How do I use Cfdump in ColdFusion?

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.

How does cfdump work?

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.

How do you declare a variable in ColdFusion?

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.


3 Answers

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

like image 73
ale Avatar answered Sep 23 '22 08:09

ale


use writeDump() like how you use writeOutput()

see writeDump on CF 9 reference

like image 45
Seeker Avatar answered Sep 25 '22 08:09

Seeker


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.

like image 37
Javier Albinarrate Avatar answered Sep 24 '22 08:09

Javier Albinarrate