Using Settings
The ColdBox Controller (stored in ColdFusion application scope as application.cbController) stores all your application settings and also your system settings:
    ColdboxSettings : Framework specific system settings
    ConfigSettings : Your application settings
You can use the following methods to retrieve/set/validate settings in your handlers/layouts/views and interceptors:
FrameworkSuperType.cfc
1
/**
2
* Get a setting from the system
3
*
4
* @name The key of the setting
5
* @defaultValue If not found in config, default return value
6
*
7
* @throws SettingNotFoundException
8
*
9
* @return The requested setting
10
*/
11
function getSetting( required name, defaultValue )
12
13
/**
14
* Get a ColdBox setting
15
*
16
* @name The key to get
17
* @defaultValue The default value if it doesn't exist
18
*
19
* @throws SettingNotFoundException
20
*
21
* @return The framework setting value
22
*/
23
function getColdBoxSetting( required name, defaultValue )
24
25
/**
26
* Check if the setting exists in the application
27
*
28
* @name The key of the setting
29
*/
30
boolean function settingExists( required name )
31
32
/**
33
* Set a new setting in the system
34
*
35
* @name The key of the setting
36
* @value The value of the setting
37
*
38
* @return FrameworkSuperType
39
*/
40
any function setSetting( required name, required value )
41
42
/**
43
* Get a module's settings structure or a specific setting if the setting key is passed
44
*
45
* @module The module to retrieve the configuration settings from
46
* @setting The setting to retrieve if passed
47
* @defaultValue The default value to return if setting does not exist
48
*
49
* @return struct or any
50
*/
51
any function getModuleSettings( required module, setting, defaultValue )
Copied!
You can also get access to these methods in handlers via the ColdBox Controller component:
1
controller.getSetting()
2
controller.getColdBoxSetting()
3
controller.setSetting()
4
controller.settingExists()
5
controller.getConfigSettings()
6
controller.getColdBoxSettings()
Copied!
or using the application scope from modules and other locations where controller isn't injected:
1
application.cbController.getSetting()
2
application.cbController.setSetting()
3
application.cbController.settingExists()
4
application.cbController.getConfigSettings()
5
application.cbController.getColdBoxSettings()
Copied!

Injecting Settings

You can use the WireBox injection DSL to inject settings in your models or non-ColdBox objects. Below are the available DSL notations:
    coldbox:setting:{key} : Inject a specified config setting key
    coldbox:coldboxSetting:{key} : Inject a specified ColdBox setting key
    coldbox:configSettings : Inject a reference to the application settings structure
    coldbox:coldboxSettings : Inject a reference to the ColdBox System settings structure
1
component{
2
3
property name="mysetting" inject="coldbox:setting:mysetting";
4
property name="path" inject="coldbox:coldboxSetting:path";
5
property name="config" inject="coldbox:configSettings";
6
property name="settings" inject="coldbox:coldboxSettings";
7
8
}
Copied!
Last modified 8mo ago
Copy link