Railo awesomeness: some cool functions and options

I've been working with the Railo source code all day, and noticed some cool functions within the code. I'm taking a minute to share 'em...

querySlice(query, startrow, rowcount)

This function returns a part of the original query, defined by the startrow and rowcount.

Documentation: http://wiki.getrailo.org/wiki/FUNCTION:QUERYSLICE

Example code:

<cfset q = querynew('column1') />
<cfset queryaddrow(q) />
<cfset querysetcell(q, 'column1', "this is row 1") />
<cfset queryaddrow(q) />
<cfset querysetcell(q, 'column1', "this is row 2") />
<!--- this will dump query 'q', but only containing row 2! --->
<cfdump var="#querySlice(q, 2, 1)#" abort />

isZipFile(filepath)

Return yes/no whether the given file path is a zip file.

Documentation: http://wiki.getrailo.org/wiki/FUNCTION:ISZIPFILE

Example code:

<cfzip action="zip" source="/" file="testZip.zip" recurse="no" />
<cfoutput>
isZipFile('testZip.zip'): #isZipFile('testZip.zip')#<br />
isZipFile( getCurrentTemplatePath() ): #isZipFile( getCurrentTemplatePath() )#
</cfoutput>

someObject["set#key#"](value)

This might also be possible (?) in the most recent versions of other CFML engines, but I sure missed it when I worked with Coldfusion 7 and 8.

When you need to update values in a CFC (bean or valueObject) by calling it's setters, but you don't know beforehand which values you need to set, then I always had to use <cfinvoke>:

<cfinvoke component="#someObject#" method="set#key#">
<cfinvokeargument value="#value#" />
</cfinvoke>

Railo allows you to use struct notation:

<cfset someObject["set#key#"](value) />

Now that's a bit shorter and cleaner!

del.icio.us Digg StumbleUpon Facebook Technorati Fav reddit Google Bookmarks
| Viewed 5029 times

No comments yet.

(will not be published)
Leave this field empty