Global Variable That Changes

19 views
Skip to first unread message

Marco & Amanda Gil

unread,
Dec 28, 2008, 3:38:56 PM12/28/08
to cfwh...@googlegroups.com

Up until now I’ve been setting a few global variables that my application requires in the onapplicationstart file.  However, I have a few variables that will change based on some URL parameters that are passed from various links/actions.  Where would be the ideal to place these variables?  My understanding is that the onapplicationstart won’t refresh itself unless reload=true, hence the need to place some of these variables I’ve mentioned above in a file that will get processed each time before an action is taken.

 

Thanks

 

Marco

Per Djurner

unread,
Dec 28, 2008, 3:48:47 PM12/28/08
to cfwh...@googlegroups.com
If this is something you want to run before ALL actions then I would
place them in the events/onrequeststart.cfm file and set them in the
request scope, i.e:
request.myVar
Then reference that variable from within your actions.

If you need to run code before SOME actions then I would recommend the
filter approach:
http://www.cfwheels.com/docs/chapter/filters-and-verification
Inside your filter function just set your variables unscoped and they
will be available to your actions (and its view pages).

/ Per

Marco & Amanda Gil

unread,
Dec 28, 2008, 11:03:10 PM12/28/08
to cfwh...@googlegroups.com
I may have missed it in the docs but follow-up question would be if there is
a variable that only changes once or twice a year based on an administrative
task done in the back-end, is there a way to force the application to reload
so that variables set in the applicationonstart are updated? I know we have
the reload=true, but is there a way of doing it without adding that to a
URL?

Thanks

Per Djurner

unread,
Dec 29, 2008, 4:38:48 AM12/29/08
to cfwh...@googlegroups.com
Yes, you can just run ColdFusion's onApplicationStart method manually:
<cfset onApplicationStart()>

Keep in mind that you probably need to put a lock around that piece of
code in production though.

/ Per

On Mon, Dec 29, 2008 at 5:03 AM, Marco & Amanda Gil <gil....@cogeco.ca> wrote:
>
> I may have missed it in the docs but follow-up question would be if there is
> a variable that only changes once or twice a year based on an administrative
> task done in the back-end, is there a way to force the application to reload
> so that variables set in the applicationonstart are updated? I know we have
> the reload=true, but is there a way of doing it without adding that to a
> URL?
>
> Thanks
>
> -----Original Message-----
> From: cfwh...@googlegroups.com [mailto:cfwh...@googlegroups.com] On Behalf
> Of Per Djurner
> Sent: Dec-28-2008 3:49 PM
> To: cfwh...@googlegroups.com
> Subject: [cfwheels] Re: Global Variable That Changes
>
>

Marco & Amanda Gil

unread,
Dec 29, 2008, 8:53:32 AM12/29/08
to cfwh...@googlegroups.com
Great thanks...

P.S - The feedback everyone provides here is great!!! The answers/responses
are always effective and to the point. I'm actually thoroughly enjoying
coding my application in large part because of cfwheels. Thanks again!!
Reply all
Reply to author
Forward
0 new messages