You are here:
node.js - built on chrome's javascript V8 engine node.js - built on chrome's javascript V8 engine

onRequestStart - variables scope

A nice little gotcha that I came across today whilst defining a new application.cfc. Within my onRequestStart method, I had defined variables within the variables scope that needed to be available to the underlying templates and application. From previous experience, I assumed that variables defined within the “variables” scope, inside the pseudo constructor of a CFC, remained local to that CFC.

However I have recently worked on a Fusebox application, that declared locally scoped variables in the OnRequestStart method, yet these variables were then available to the underlying application. This got me thinking ..... How?

After a bit of discussion amongst the team I’m currently working with, Dominic Watson suggested adding the "onRequest" method to the application.cfc and passing the target page to this method. This is exactly how the previous Fusebox application worked. The example method is detailed below:

<cffunction name="onRequest" output="true" returnType="void" access="public">
<cfargument name="targetPage" type="String" required="true" />
<cfinclude template="#arguments.targetPage#" />
</cffunction>

So with this method now added, I fired the application and dumped the variables scope. Voila! my variables were available. Thanks to Dom for saving me some "banging my head against the wall" time!