Interacting-With-Settings

<< Back to Dashboard

Contents

Interacting With Settings

Covers up to version 3.5.0

The Internal Structures


ColdBox uses two internal structures in order to configure and run your applications. One is the ColdBox Settings and the other is the Configuration Settings , which are created on the application's initial request. The ColdBox Settings and the Configuration Settings reside inside the ColdBox application controller, which is the object that models your application and lives in the application scope. Please remember that your application can be reinitialized by using the fwreinit=1 URL param. See URL Actions.

  • ColdboxSettings : Framework specific settings.
  • ConfigSettings : Your application settings.


As you can see from the diagram above, when you work with ColdBox, you will be working with handlers, interceptors, plugins, layouts, and views. All of these objects pivot around a main super class called the Framework Super Type which has access to the application's controller and provides you with tons of useful methods for interacting with your application.

Configuration Settings

The Configuration Settings Structure is the structure that gets created according to your configuration file. All your application settings are here. You can retrieve any setting (key) from this structure by using the getSetting() method call, which you can do from your event handlers, plugins, interceptors, layouts and views thanks to the super type. You can also create new settings programmatically by using the setSetting() method. You can also verify that a setting value exits by using the settingExists() method. There are also several methods available to you that interact with this structure like retrieving webservice's URLs or creating web service objects from the URLs, getting datasource beans, getting resource bundle keys, etc. The best place to start for all these methods, is for you to study the CFC API.

Note: However, please understand that those settings that you set manually will only exist for that application's lifespan. Once the application times out, those settings will be lost. So please note that if you set dynamic settings, you need to have a mechanism of reloading them as the application starts again. Usually on the Application Start Handler or an interceptor that executes afterConfigurationLoad or afterAspectsLoad

Common Setting Methods

  • getSetting([string name], [boolean FWSetting], [defaultValue])
  • getModuleSettings(module)
  • setSetting([string name], [any value])
  • settingExists([string name], [boolean FWSetting])
  • getSettingStructure([boolean FWSetting], [boolean DeepCopyFlag])
  • controller.getConfigSettings()
  • controller.getColdboxSettings()
  • getSettingsBean() : construct a coldbox.system.core.collections.ConfigBean with all the application settings.

FWSetting = Boolean Flag to use the framework settings structure instead of the application settings structure

Code Samples

//Get a setting
<cfset getSetting("key")>

//Get the settings structure using controller getter method
<cfset getSettingStructure(false)>

//Set a new setting
<cfset setSetting("key",value)>

//Check if setting exists
<cfset settingExists("key")>

//get the framework structure settings
<cfset frameworkSettings = controller.getColdboxSettings()>

//get the application settings
<cfset appSettings = controller.getConfigSettings()>

//Construct a configuration bean with all of my configuration settings
<cfset configBean = getSettingsBean()>

Settings In The Model

The model is a completely isolated layer of your appliction and has no access to anything ColdBox unless you inject dependencies into them. We suggest you look at our WireBox dependency injection so you can see how to inject the models with what they need.

 
Download in other Formats:
markup Markup | pdf PDF | html HTML | word Word

comments Comments (0)


ColdBox Book

book