$config¶
$config is the variable that contains all the data displayed for editing in /setup.
Use¶
When naming your entries, also consider that name clashes will result in multiple extensions using and changing the variable, leading to unpredictable behaviour in both your extension and the other extension. To avoid this problem, prefix your entries with the name of your extension.
For example, the hypothetical extension hello_world has one option, which supplies the text the extension prints to the screen. There are a few possible names:
Retreival¶
Variables contained within $config may be accessed using
global $config;
$config->get_string("<variable_name>");
$config->get_int("<variable_name>");
$config->get_bool("<variable_name>");
Storing¶
Conversely, variables may be set (or created if it doesn't exist) using
$config->set_string("<variable_name>", $some_string);
$config->set_int("<variable_name>", $some_integer);
$config->set_bool("<variable_name>", $some_boolean);
Default Entries¶
For one-off cases, each of the get_X() functions takes an optional second argument to be used if the value isn't set in the database.
If a value is used in many places, you can call $config->set_default_X($name, $value) during an InitExtEvent. This will set the value only if there's no setting in the database.