The Config System
Remarks#
What is the config system
SilverStripe uses a global config system to store settings for classes and the application. These config variables can be used to define the structure of Models, security settings on Controllers or API keys for third party services.
How it works
Config values are populated by the SS_ConfigStaticManifest during a dev/build and cache flush (appending ?flush to any URL`) or on first ever run of the application code.
The SS_ConfigStaticManifest will scan all PHP classes and YAML config files for any config values and build a cache of these values.
When making change to
Configsettings via YAML orprivate staticvariables, you’ll need to flush the cache for these changes to take effect.
Setting config values
Config values can be set in three ways:
- Via
private staticvariables on any class within a SilverStripe project - Via yaml config files (stored in module-folder/_config/[file].yml)
- Via PHP at run time (
Config::inst()->update('Director', 'environment_type', 'dev')
Generally it’s best to set config values via the first 2 methods as these are statically cached when flushing the cache.
Setting with private statics
class MyDataObject extends DataObject {
private static $db = array(
'Title' => 'Varchar',
);
}All
private staticclass variables in a SilverStripe project’s code (including modules, but not packages in thevendor/directory) will be loaded into theConfig.
Setting with YAML
You can add this to mysite/_config/config.yml (or any other YAML file in that path).
Director:
environment_type: devUsing YAML files is a great way to override default
Configvalues for core classes or modules
Setting at runtime
This would typically be done in mysite/_config.php
Config::inst()->update('Director', 'environment_type', 'dev');Updating the
Configin PHP should be avoided where possible as it’s slower than using the cached values