Search code examples
coldfusioncoldfusion-9

Where is dump function in cfscript?


Possible Duplicate:
How to do a cfdump inside a cfscript tag?

I'm new to Coldfusion and wondered if anyone knew of a way to access function when inside a script block. I cant find way of calling it from there.

Why have Adobe removed it? Or have they just called it something else now?

Sorry - I know this is probably really basic question, but like I said I'm new.


Solution

  • writeDump()

    Apparently in ColdFusion 9 it has been added as writeDump() so you should be able to use this from a cfscript block.

    So if you have CF9, then you are fine.

    If you using an older legacy system which does not support this newly introduced writeDump() function, as we are, you could write a wrapper for it and put it somewhere accessible to all your files.

    This is the wrapper I have written, which for short term debugging use can be put on the cfc file you are working on (although remove it before you commit your code - otherwise it's just a mess), or you can put it somewhere global so you can call it from shared scopes.

    Here is an example of a wrapper function you can use:

    <cffunction name="dump" access="private" returntype="void" hint="dump wrapper">
        <cfargument name="stuffToDump" type="any" required="true" hint="what you want to dump">
        <cfargument name="abort" type="any" default="false" hint="abort after dump">
        <cfargument name="expand" type="any" default="false" hint="expand output">
        <cfdump var="#arguments.stuffToDump#" expand="#arguments.expand#">
        <cfif #arguments.abort# EQ 1>
            <cfabort>
        </cfif>
    </cffunction>
    

    There are probably better ways around this problem, but this is what I currently use.

    You can put it (temporarily) on the cfc file that you are currently working on, but obviously don't commit this to your code base as you don't want the dump function on all your files.

    Or you could put it permanently onto a cfinclude file, and just include that (again - temporarily) to files you are debugging.

    Another alternative I guess is to put it onto the Application.cfc. This file has a number of standard methods but you can also define your own additional methods to be included into it. Then you have your dump() function available in the APPLICATION scope.

    There's a good info page on the Application.cfc file here. http://www.bennadel.com/blog/726-ColdFusion-Application-cfc-Tutorial-And-Application-cfc-Reference.htm

    I have even seen it used in the Server scope, but this should never be done on production code. OK for debugging I guess as a last resort, just make sure you remember to remove it.

    Personally I think both these options are probably far from ideal, and it's a great shame it took Adobe so long to provide a script alternative to the function. Would have saved a lot of pain.

    But hopefully if you are using CF9 then all this will be irrelevent to you and you can just use the new writedump() function now they have finally added it in.