I had this question in a job interview once, 'which Application.cfc method
shares the variables scope with the rest of the application?'. I, of course,
said, 'none of them do, the variables scope is local to the application' and
they said that the correct answer was 'onRequest' - total hogwash.

The variables scope *is* local to the cfc. However, you can use the
OnRequest method to include the requested template, which means that all
your code is now local to the cfc instance and shares its variables scope.
So:

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

HTH

Dominic

2009/11/2 Stefan Richter <[email protected]>

>
> I'm trying to set a few variables in my Application.cfc file and I'm a
> bit confused about scopes.
>
> Here's what I have got:
>
>   <cffunction name="onApplicationStart">
>
>         <cfset APPLICATION.page_title = "My Title">
>        <cfreturn True>
>
> </cffunction>
>
>
> I can access this anywhere in my site as #APPLICATION.page_title#. But
> if I leave off the APPLICATION and write
>  <cfset page_title = "My Title"> and then try to access a variable
> #page_title# CF9 throws an error, saying the variable is not defined
> (I restarted CF before testing this).
> Variable PAGE_TITLE is undefined.
>
>
>
> Why does this happen? Do I really need to prefix all variables with
> APPLICATION? According to the debugger a variable defined in
> Application.cfc without the APPLICATION prefix does not exist in any
> scope.
>
> Stefan
>
>
>
>
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:327900
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to