This little gem makes me giddy all over - and I don't get giddy easily. There was that one time at a Bette Midler concert in ‘99.... but I digress. Here's a method you may find useful during development, debugging and possibly for error handling. It's a method of the getPageContext() function that returns all scopes available to the request. That would be:
- Variables
- Form
- Cffile
- cfthread
- Request
- Server
- Http
- Cgi
- Client
- URL
- Session
- Cookie
- File
- Application
This tag does you a favor in that it guarantees that the scope will be there. So you don't have to "test" for session and then dump out or handle session. It will just show up for you. Here's the code:
getBuiltInScopes()
<cfdump var="#getPageContext().getBuiltInScopes()#"/>
There are few caveats. First, you can't set the return value more than once per page without causing some trouble (well... you can, but you would have to remove the first reference). Secondly, if you do set the result to a return value and then try to dump that object the page will hang. For example:
<cfscript>
allScopes = getPageContext().getBuiltInScopes();
</cfscript>
<cfdump var="#allScopes#"/>
Why does this hang while <cfdump var="#getPageContext().getBuiltInScopes()#"> works fin? Because the "variables" scope is one of the scopes that is a part of the "getBuiltInScopes()" function. So you are create a problem for the dump routine. It is trying to dump variables which contains a reference to variables which contains a reference to variables etc. The little man in the Coldfusion engine is getting wheezy and cross-eyed trying to give you the whole banana. You can however, reference and dump any key
except variables like so:
<cfset allScopes = getPageContext().getBuiltInScopes()/>
<cfloop list="#structKeyList(allscopes)#" index="k">
<cfif k IS NOT 'variables'>
<cfoutput> <h4>#k#</h4></cfoutput>
<cfdump var="#allscopes[k]#"/>
</cfif>
</cfloop>
In any case it's just one more arrow in the quiver of the well armed Coldfusion Warrior. Happy hunting.