tags:

views:

482

answers:

3

Hi Can one use cfdump inside a cfcomponent? Can one use cfdump inside a cfscript?

I know the anser is no then how can one emit the values of the functions insde cfcomponent cfscript? I am using CF8

A: 

cfdump inside cfcomponent? why not... But I think you should do it in a cffunction.

cfdump inside cfscript? WriteDump() in CF9, or search cflib for a UDF that works in CF6+

Henry
+5  A: 

Can one use cfdump inside a cfcomponent?

Yes, with some caveats. If you use a CFDUMP followed by CFABORT, the dump will be displayed whether or not the component/method has output turned off. That does, of course, abort all processing.

Can one use cfdump inside a cfscript?

Not exactly (unless you're using CF9), but there are workarounds.

You can close your script, put in the dump tag, then re-open it, like so:

</cfscript><cfdump var="#myVar#"><cfscript>

There is also a UDF at CFLib that mimics the CFDUMP tag.

Dump

Added: In CF9 or later, there is also writeDump().

Al Everett
There's WriteDump() in CF9
Henry
Yes, of course. But I don't have CF9 here and was in the middle of looking it up in the CFML reference. I've edited my answer.
Al Everett
+1  A: 

Coldfusion 9:

<cfscript>
    myVar = "this is a test";
    WriteDump(myVar); 
</cfscript>

Coldfusion 8 and below: CF 8 does not have a cfscript version of the tag, so if needed, it needs to be abstracted into a user defined function first. This function will need to be accessible to your component.

I avoided the name "WriteDump()" to prevent any possible conflict if this code is used with CF9.

<!--- Abstract cfdump tag for use in cfscript --->
<cffunction name="scriptDump" output="no" hint="Abstracts cfdump for cfscript">
    <cfargument name="myVar" required="yes">
    <cfset var result = "">

    <cfsavecontent variable="result">
        <cfdump var="#arguments.myVar#">
    </cfsavecontent>

    <cfreturn result>
</cffunction>

<cfset myVar = "this is a test">

<!--- Test the scriptDump(var) function in cfscript --->
<cfscript>
    dumpOfMyVar = scriptDump(myVar);
</cfscript>

<!--- Test the scriptDump(var) function in regular HTML --->
<cfoutput>
    #scriptDump(myVar)#
</cfoutput>
Dan Sorensen