Wednesday, April 25, 2007

BEN FORTA: Scorpio Per Application Settings

Taken from: http://www.forta.com/blog/index.cfm/2007/4/24/Scorpio-Per-Application-Settings

ColdFusion users have long wanted a way to define settings per application, rather than server-wide. In truth, this is doable right now, just install multiple instances of ColdFusion an each instance gets its own CF Admin and own settings.

But, if that is not an option, then Scorpio will help, as I explained last night in Seattle. ColdFusion MX7 introduced Application.cfc as an alternative to Application.cfm. Application.cfc does everything that Application.cfm does, and added important new features (like methods that get executed OnSessionStart and OnSessionEnd).

To set application settings using Application.cfc, variables are set in the THIS scope. THIS.name to set the application name, THIS.sessionManagement to enable session state management, and so on.

In Scorpio, Application.cfc and the THIS scope can be used to define per application settings. For example, THIS.mappings is a structure which contains the currently defined ColdFusion mappings.

To set a mapping you just modify that structure like this:

<cfset THIS.mappings["MyStuff"]="c:\inetpub\MyStuff">

Or like this:

<cfset StructInsert(THIS.mappings, "MyStuff", "c:\inetpub\myStuff")>

To set the Custom Tag path you can update THIS.customtagpaths which is a simple ColdFusion list.

You can set the path like this:

<cfset THIS.customtagpaths="c:\inetpub\wwwroot\ben\tags">

Or use ListAppend() to add a path, like this:

<cfset THIS.customtagpaths=ListAppend(customtagpaths, "c:\inetpub\wwwroot\ben\tags")>

You get the idea. It's clean, simple, and highly intuitive. Which means you now have yet another reason to use Application.cfc.

No comments: