Model Glue : Setting up global variables

Unlike Fusebox there is not a global init variable setting file With MG. If you do need to set up some global vars the way i'm doing this (and seems to be the norm nearly) is:

  1. Set up a cfc called /config/beans/global.cfc
  2. Create an xml file at /config/beans/global.xml - (for my current site this covered about 5-8 small structures/arrays/values that is used through out the site)
  3. In the controller add the following line -
    <cfset variables.global = GetModelGlue().GetConfigBean("global.xml") />
  4. and on request start -
    <cfset arguments.event.setValue("global", variables.global) />

Now on any page to get the variable you want you can use
view plain print about
1<cfset customerTitles = viewState.getValue('global').getTitles() />

I've seen no documentation on this, but have posted to the Topica List. Sean Corfield has another method using a new controller you can find it on the Topica lists also see the GGCC examples (7/8/9) in his frameworks Pod.


For more information on Config beans in MG see :
Eat Your Beans: ConfigBeans in Model-Glue

Posted: 06-Dec-2005

View: 2907

Permalink: here

Comments

You can also set the variables in ModelGlue.xml, as a simple setting.

<setting name="dsn" value="universitynotesnet" />

You can use them later in onRequestStart in your controller like so:

<cfset arguments.event.setValue("dsn", getModelGlue().getConfigSetting("dsn"))>

#1 Raymond Camden
06/Dec/05 12:39 PM

Cheers Ray, I should of mentioned this is more for holding struct/array variables. Though at the moment i'm leaning towards putting them all there for consistency

#2 Andy J
06/Dec/05 1:43 PM

Thanks for the post Andy - another method to try out in my quest to figure out the best way of setting up global config variables in MG.

One thing though, you don't say what the global.cfc is actually used for and what should be in it.

Could you please elaborate.

#3 James Allen
21/Nov/07 9:45 AM