CF Coding Practices
  • General Coding Practices
  • Debugging JSON-based CFC Methods
    • Valid JSON Formatting
    • Validating JSON
    • Final Hints
  • How We Invoke Modals
  • Submit Handlers
  • Useful SQL Snippets
  • jQuery/JS How-Tos And Hints
  • jQuery dataTables Tricks
  • CFSCRIPT Snippets and Hints
  • StatusPage Integration
  • Windows Server Setup
  • Common CF Formatting Commands
  • CF Snippets & Hints
  • Developing With The Mura Platform
    • ContentRenderer.CFC
    • Iterators
    • Iterating Remote Feeds
    • Components
    • Nested Content and Interactive Page Assembly
    • Modules and Display Objects
Powered by GitBook
On this page
  • writeDump
  • Virtual File System

Was this helpful?

CF Snippets & Hints

Common crap that you run across with ColdFusion

writeDump

writeDump() can cause an issue when used in a CFC. For example, if you try the following in a CFC method, you'll get a "Method writeDump with 1 arguments is not in class coldfusion.runtime.CFComponent" error:

filewrite('C:\websites\Test\debug\debugFile1.html', writeDump(arguments);

Obviously writeDump is a build in CF method*, so this error makes little since. The work-around is to use the savecontent method/command and save the writeDump() output to that like this:

savecontent variable='dump' {writedump(arguments);}
filewrite('C:\websites\Test\debug\debugFile1.html', dump;

*NOTE: Adam Cameron has a blog where he examined this very issue and made the following observation, "The issue seems to be down to poor implementation of the inbuilt [sic] ColdFusion functions which take name/value pairs as arguments: throw(), writeDump(), writeLog(). None of them work properly as functions." This was noted back in 2014 and remains unresolved to this day.

Virtual File System

Starting with CF9, ColdFusion makes a RAM-based virtual file system (VFS) available for reading file-based information into memory to be used immediately. This provides an excellent alternative to fetching remote data and storing it first on the server file system when it isn't needed to preserve the data.

The following code shows an example of fetching a remote RSS file, storing it in the VFS, and then looping through it's content for display:

<cfset source = "http://remoteRSSsource/resource/rss/events.rss"> 
<cfhttp url="#source#" method="GET"> 
<cfset randFileName = "ram:///#createUUID()#.txt"> 
<cfset fileWrite(randFileName, cfhttp.filecontent)>
<cffeed query="rs" source="#randFileName#" />
<cfset it = $.getBean('beanIterator').setQuery(rs) />
<cfif it.hasNext()>
	<table class="table">
		<cfloop condition="it.hasNext()">
			<cfset content = it.next()/>
			<tr>
				<td><a href="#content.getValue('rssLink')#" target="_blank">#content.getValue('Title')#</a></td>
				<td>#DateFormat(content.getValue('publisheddate'),'m/d/yyyy')#</td>
			</tr>
		</cfloop>
	</table>
</cfif>
PreviousCommon CF Formatting CommandsNextDeveloping With The Mura Platform

Last updated 6 years ago

Was this helpful?