Skip to content

Application config variables

Jason Austin edited this page Aug 19, 2013 · 1 revision

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.

Registering a config variable

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().

Retrieving a config variable

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.

Action Helper

You can call the configVar action helper to retrieve the value of an action helper easier.

$this->_helper->configVar('defaultFrom');

View Helper

You can call the configVar view helper from a view to get the value easier as well.

echo $this->configVar('defaultFrom');

Setting a config variables value

To set the value of a config variable, go to App Config in your admin menu of your OTF app.

Creating your own config variable type

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.