onapplicationstart.cfm - global variable

430 views
Skip to first unread message

MrBubusch

unread,
Jun 4, 2010, 9:23:13 AM6/4/10
to ColdFusion on Wheels
Hi

I want to set a variable globally for my application and I understand
it needs to go in /events/onapplicationstart.cfm.

So I included <cfset uploadPath = 'data etc' /> in that page but the
application isn't picking it up despite a reload.

I'm referencing it using #uploadPath# but I get an error "Variable
UPLOADPATH is undefined".

Am I declaring or referencing this variable incorrectly?

Thanks

James

Andy Bellenie

unread,
Jun 4, 2010, 9:42:52 AM6/4/10
to cfwh...@googlegroups.com
Hi James,

What kind of variable do you want it to be?

Anything you set in onapplicationstart.cfm will only exist when the
application is first started, unless you put it into a persisitant
scope, e.g

<cfset application.uploadPath = "data">

/ Andy

> --
> You received this message because you are subscribed to the Google Groups "ColdFusion on Wheels" group.
> To post to this group, send email to cfwh...@googlegroups.com.
> To unsubscribe from this group, send email to cfwheels+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/cfwheels?hl=en.
>
>

Mike Henke

unread,
Jun 4, 2010, 9:46:03 AM6/4/10
to ColdFusion on Wheels
I am kinda foggy since I not used or seen an example of /config/
app.cfm but it might be what you are looking for.

<!---
Place settings that should go in the Application.cfc's "this" scope
here.
<cfset this.name = "MyAppName">
--->

Also here is another link about global variables.

Using set() for custom global variables -
http://groups.google.com/group/cfwheels/browse_thread/thread/9ed5b77d6e203bf/a9c9acab7c18110f

There is some disagreement about the technique but I can't find that
thread. I use this technique and it works.

Andy Bellenie

unread,
Jun 4, 2010, 9:58:05 AM6/4/10
to cfwh...@googlegroups.com
When setting application variables I prefer to put them inside
/config/settings.cfm as this is called whenever you call ?reload

MrBubusch

unread,
Jun 4, 2010, 10:25:49 AM6/4/10
to ColdFusion on Wheels
Thanks guys I've taken this approach:

Declare your variables in /config/settings.cfm like so:

<cfset loc.myapp = {}>
<cfset loc.myapp.title = 'E-Reports | Spend Analytics' />
<cfset loc.myapp.applicationPath = '/Applications/ColdFusion9/wwwroot/
e-reports/'>
<cfset set(myapp = loc.myapp)>

And call them with e.g. <cfoutput>#get("myapp").title#</cfoutput>

Thanks
James


On Jun 4, 2:58 pm, Andy Bellenie <andybelle...@gmail.com> wrote:
> When setting application variables I prefer to put them inside
> /config/settings.cfm as this is called whenever you call ?reload
>
> On 4 June 2010 14:46, Mike Henke <henkem...@gmail.com> wrote:
>
>
>
> > I am kinda foggy since I not used or seen an example of /config/
> > app.cfm but it might be what you are looking for.
>
> > <!---
> >        Place settings that should go in the Application.cfc's "this" scope
> > here.
> >        <cfset this.name = "MyAppName">
> > --->
>
> > Also here is another link about global variables.
>
> > Using set() for custom global variables -
> >http://groups.google.com/group/cfwheels/browse_thread/thread/9ed5b77d...

Per Djurner

unread,
Jun 7, 2010, 5:35:07 AM6/7/10
to cfwh...@googlegroups.com
@Andy: The events/onapplicationstart.cfm file is also executed on
?reload so to me it makes more sense to put settings there.
Reply all
Reply to author
Forward
0 new messages