-
Notifications
You must be signed in to change notification settings - Fork 2
Application config variables
OTF provides a mechanism to allow developers to register application config variables that can be used throughout the system. The values of these variables can be set by the application administrators. This is helpful in cases such as default from addresses for emails, or date formats, or certain passwords that may change over time.
Config variables should be registered in your bootstrap file. Config variables must be of type Ot_Var_Abstract to be registered.
$vars[] = new Ot_Var_Type_Text('defaultFrom', 'Default From Address', 'Default from email address.', 'default@app.com');
$vr = new Ot_Config_Register();
$vr->registerVars($vars, 'My Settings');
This would register the variable defaultFrom
with a default value of default@app.com
. You can group config variables together by specifying the second argument in registerVars().
To retrieve the value of the config var, you will need to get it from the registry first.
$vr = new Ot_Config_Register();
$defaultFrom = $vr->getVar('defaultFrom');
echo $defaultFrom->getValue();
This will echo the value in the defaultFrom
custom variable.
You can call the configVar action helper to retrieve the value of an action helper easier.
$this->_helper->configVar('defaultFrom');
You can call the configVar view helper from a view to get the value easier as well.
echo $this->configVar('defaultFrom');
To set the value of a config variable, go to App Config in your admin menu of your OTF app.
It may be a requirement for you to create a new type of config variable type that is not part of the base OTF types provided. To do that, you must only extend Ot_Var_Abstract. Then you can instantiate a new version of that class and assign it in your bootstrap just like any OTF-provided var type.