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
/**
* Get a setting from the system
* @name The key of the setting
* @fwSetting Retrieve from the config or fw settings, defaults to config
* @defaultValue If not found in config, default return value
*/
function getSetting( required name, boolean fwSetting=false, defaultValue )
/**
* Verify a setting from the system
* @name The key of the setting
* @fwSetting Retrieve from the config or fw settings, defaults to config
*/
boolean function settingExists( required name, boolean fwSetting=false )
/**
* Set a new setting in the system
* @name The key of the setting
* @value The value of the setting
*
* @return FrameworkSuperType
*/
any function setSetting( required name, required value )

You can also get access to these methods in handlers via the ColdBox Controller component:

controller.getSetting()
controller.setSetting()
controller.settingExists()
controller.getConfigSettings()
controller.getColdBoxSettings()

or using the application scope from modules and other locations where controller isn't injected:

application.cbController.getSetting()
application.cbController.setSetting()
application.cbController.settingExists()
application.cbController.getConfigSettings()
application.cbController.getColdBoxSettings()

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

component{
property name="mysetting" inject="coldbox:setting:mysetting";
property name="path" inject="coldbox:coldboxSetting:path";
property name="config" inject="coldbox:configSettings";
property name="settings" inject="coldbox:coldboxSettings";
}
Edit on GitHub