Thursday 24 April 2014

CFDUMP, and how I'm a bit thick

G'day:
This isn't even a case of me not RTFMing and then discovering something I didn't know. I knew this already. But am just a bit dense.

I'm perennially doing this sort of thing:

private function logArgs(required struct args, required string from){
    savecontent variable="local.dump" {
        writeDump(var=args, label=from);
    }
    fileWrite(getDirectoryFromPath(getCurrentTemplatePath()) & "dump_#from#.html", local.dump);

(As case in point being: I just wrote that code for a new blog article that I should have done and dusted by this evening)

However I don't need to do that. I can just do this:

private function logArgs(required struct args, required string from){
    var dumpFile = getDirectoryFromPath(getCurrentTemplatePath()) & "dump_#from#.html";
    if (fileExists(dumpFile)){
        fileDelete(dumpFile);
    }
    writeDump(var=args, label=from, output=dumpFile, format="html");
}

I'm so accustomed to only every using the var argument, and occasionally the label one, I tend to forget there's a bunch of other options on <cfdump> / writeDump() as well (from the docs):

AttributeReq/OptDefaultDescription
varRequiredVariable to display. Enclose a variable name in number signs. These kinds of variables yield meaningful cfdump output
expandOptionalyes
  • yes: in Internet Explorer and Mozilla, expands views.
  • no: contracts expanded views.
formatOptionaltextUse with the output attribute to specify whether to save the results of a cfdump to a file in text or HTML format.
hideOptionalallFor a query, this is a column name or a comma-delimited list of column names. For a structure, this is a key or a comma-delimited list of keys.
If you specify a structure element that doesn't exist, ColdFusion ignores it and does not generate an error.
keysOptional9999For a structure, the number of keys to display.
labelOptionalA string; header for the dump output. Ignored if the value of the var attribute is a simple types.
metainfoOptionalyes for query
no for persistence CFCs
For use with queries and persistence CFCs. Includes information about the query in the cfdump results, including whether the query was cached, the execution time, and the SQL. Specify metainfo="no" to exclude this information from the query result. For persistence CFCs, if metainfo="yes", returns property attributes such as getters and setters.
outputOptionalbrowserWhere to send the results of cfdump. The following values are valid:
  • browser
  • console
  • filename
    The filename must include the full pathname of the file. You can specify an absolute path, or a path that is relative to the ColdFusion temporary directory. You can use the GetTempDirectory() function to determine the ColdFusion temporary directory.
showOptionalallFor a query, this is a column name or a comma-delimited list of column names. For a structure, this is a key or a comma-delimited list of keys.
showUDFsOptionalyes
  • yes: includes UDFs, with the methods collapsed.
  • no: excludes UDFs.
topOptional9999The number of rows to display. For a structure, this is the number of nested levels to display.
abortOptionalfalseIf this attribute is set to "true", it stops processing the current page at the tag location.

Perhaps everyone else in the world remembers all this stuff and uses it all the time. I'm simply not that clever.

--
Adam