Config
concrete5 provides the Config class to enable the easy saving and loading of configuration data. This data can be associated with certain packages, as well as certain user accounts. The table is a simple key/value store.
Saving Data
Config::save($key, $value)
Saves a string or numeric $value with the key of $key in the Config database table.
Config::save('favorite_candy', 'chocolate');
Config::get($key)
Gets the data saved for key $key.
Config::get('favorite_candy');
If $getFullObject is true, an object of the ConfigValue type will be returned. This object contains the following properties:
- $timestamp - date the configuration value was saved.
- $key - the key for this value.
- $value - the value.
Config::clear($key)
Clears the entry for key $key.
Specifying a Package with Your Data
The Config library also supports binding data to keys within certain packages. For addon developers, it's a good idea to specify a package so that 1) you are guaranteed no one else will use your configuration key, and 2) your data will be removed if your package is uninstalled.
Example
$co = new Config();
$pkg = Package::getByHandle("calendar");
$co->setPackageObject($pkg);
$co->save('calendar_mode', 'monthly');
$co->save('calendar_start', 1);
Saving Data Against Specific User Accounts
The following example saves and retrieves data against the logged-in user account
$u = new User();
$u->saveConfig('favorite_color', 'red');
print $u->config('favorite_color');