Where do you set application wide variables?

229 views
Skip to first unread message

Mohamad El-Husseini

unread,
Dec 16, 2010, 12:40:12 PM12/16/10
to ColdFusion on Wheels
Let's say I have a few global variables I need to set, where would
they go? For example, I have the following variables for a sanitize
function:

<cfset variables.reTags = '<[^>]*(>|$)'>
<cfset variables.reWhitelist = '(?x) ^</?(b(lockquote)?|code|d(d|t|l|
el)|em|h(1|2|3)|i|kbd|li|ol|p(re)?|s(ub|up|trong|trike)?|ul)>$ | ^<(b|
h)r\s?/?>$'>

I can set them in the Post.cfc model, but what if I had ones that
needed to be global?

raulriera

unread,
Dec 16, 2010, 3:12:24 PM12/16/10
to ColdFusion on Wheels
You can place them at /config/app.cfm :)

Mohamad El-Husseini

unread,
Dec 17, 2010, 11:46:37 AM12/17/10
to ColdFusion on Wheels
Raul, thanks. Do they take the application scope?

I just tried this in config/app.cfm

<cfset application.award = 10>

But calling application.award from the my Model gives an "award" is
not defined in application.

craig.kaminsky

unread,
Dec 17, 2010, 12:28:20 PM12/17/10
to cfwh...@googlegroups.com
I'm not sure if this is ideal for CFWheels, but I use the following in /config/settings.cfm
<cfscript>
loc.app = {};
loc.app.companyName = "Comany Name";
loc.app.defaultEmail = "in...@mydomain.com";
loc.app.webmasterEmail = "webm...@mydomain.com";
loc.app.companyAddress = "PO BOX123 Anytown, CO 12345";
loc.app.companyPhone = "111-555-1212";
loc.app.reloadURL = "http://" & cgi.http_host & "/?reload=true&password=pass";

// set application variables
set(app=loc.app);    
set(errorEmailAddress=loc.app.webmasterEmail);
set(errorEmailSubject="OurayClimbing.com Wheels Error");
set(reloadPassword="bruin2big");
set(transactionMode="none");
</cfscript>

In my /config/app.cfm, I tend to put the standard Application.cfc variables:
<cfscript>
this.name = "My App Name";
//etc ...
</cfscript>

This has worked great for me, but, I'm fairly new to CFWheels and this might not be a best-practice. 

Chris Peters

unread,
Dec 17, 2010, 1:11:19 PM12/17/10
to cfwh...@googlegroups.com
config/app.cfm maps directly to the Application.cfc's onApplicationStart. Usually you only use that file to set ColdFusion settings like SessionManagement. Because of this, you use the this scope to set application values.

this.award becomes application.award elsewhere in your app I believe.

I recommend setting application scope variables in events/onapplicationstart.cfm:
<cfset application.award = 10>

Some prefer to use config/settings.cfm as well, but I tend to only use that for Wheels settings.

It all depends on your preferences and what makes most sense to you.


--
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.


raulriera

unread,
Dec 17, 2010, 5:32:43 PM12/17/10
to ColdFusion on Wheels
Chis is right, forget about me... :)

On Dec 17, 7:11 pm, Chris Peters <ch...@clearcrystalmedia.com> wrote:
> config/app.cfm maps directly to the Application.cfc's onApplicationStart.
> Usually you only use that file to set ColdFusion settings like
> SessionManagement. Because of this, you use the this scope to set
> application values.
>
> this.award becomes application.award elsewhere in your app I believe.
>
> I recommend setting application scope variables in
> events/onapplicationstart.cfm:
> <cfset application.award = 10>
>
> Some prefer to use config/settings.cfm as well, but I tend to only use that
> for Wheels settings.
>
> It all depends on your preferences and what makes most sense to you.
>
> On Fri, Dec 17, 2010 at 11:46 AM, Mohamad El-Husseini <abitdo...@hotmail.com
>
>
>
> > wrote:
> > Raul, thanks. Do they take the application scope?
>
> > I just tried this in config/app.cfm
>
> > <cfset application.award = 10>
>
> > But calling application.award from the my Model gives an "award" is
> > not defined in application.
>
> > On Dec 16, 6:12 pm, raulriera <rierar...@gmail.com> wrote:
> > > You can place them at /config/app.cfm :)
>
> > > On Dec 16, 6:40 pm, Mohamad El-Husseini <abitdo...@hotmail.com> wrote:
>
> > > > Let's say I have a few global variables I need to set, where would
> > > > they go? For example, I have the following variables for a sanitize
> > > > function:
>
> > > >         <cfset variables.reTags = '<[^>]*(>|$)'>
> > > >         <cfset variables.reWhitelist = '(?x)
> > ^</?(b(lockquote)?|code|d(d|t|l|
> > > > el)|em|h(1|2|3)|i|kbd|li|ol|p(re)?|s(ub|up|trong|trike)?|ul)>$ | ^<(b|
> > > > h)r\s?/?>$'>
>
> > > > I can set them in the Post.cfc model, but what if I had ones that
> > > > needed to be global?
>
> > --
> > 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<cfwheels%2Bunsubscribe@googlegroups.c om>
> > .

Mohamad El-Husseini

unread,
Dec 17, 2010, 7:07:14 PM12/17/10
to ColdFusion on Wheels
Thanks guys, that makes sense.
> > > cfwheels+u...@googlegroups.com<cfwheels%2Bunsubscr...@googlegroups.c om>

Joey Daly

unread,
Dec 19, 2010, 9:01:20 PM12/19/10
to cfwh...@googlegroups.com
+4 to craig - i use this concept too. I hate having to check multiple files for "application" settings.

--
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.

Risto

unread,
Dec 21, 2010, 5:33:42 PM12/21/10
to ColdFusion on Wheels
Craig,

So you can only access the variables you set with get() not
application. ?

On Dec 17, 12:28 pm, "craig.kaminsky" <craig.kamin...@gmail.com>
wrote:
> I'm not sure if this is ideal for CFWheels, but I use the following in
> /config/settings.cfm
> <cfscript>
> loc.app = {};
> loc.app.companyName = "Comany Name";
> loc.app.defaultEmail = "i...@mydomain.com";
> loc.app.webmasterEmail = "webmas...@mydomain.com";

Joey Daly

unread,
Dec 21, 2010, 5:48:55 PM12/21/10
to cfwh...@googlegroups.com
Hey Risto,

Using set() is appends to the 'application' scope. So if you do <cfdump var="#application#"> you should see the variables you set.

So to pull that information back out (using Craig's example code), you simply do #get("app").defaultEmail# in you're view.

Hopefully that makes a bit more sense :P


Risto

unread,
Dec 21, 2010, 8:10:19 PM12/21/10
to ColdFusion on Wheels
Nice.

You wouldn't believe how many combination's I tried within the double
quotes:)

Thanks.



On Dec 21, 5:48 pm, Joey Daly <joey...@gmail.com> wrote:
> Hey Risto,
>
> Using set() is appends to the 'application' scope. So if you do <cfdump
> var="#application#"> you should see the variables you set.
>
> So to pull that information back out (using Craig's example code), you
> simply do #get("app").defaultEmail# in you're view.
>
> Hopefully that makes a bit more sense :P
>
> > cfwheels+u...@googlegroups.com<cfwheels%2Bunsu...@googlegroups.com>
> > .
Reply all
Reply to author
Forward
0 new messages