Working with Config

Chyrp Lite's Config class provides an interface to get and set persistent configuration settings for the site. Extension authors are strongly encouraged to use the Config class to store all settings required by an extension. The optimal place to add settings is in the __install() method of a module or feather. Settings should be removed in the __uninstall() method when the extension is disabled.

Access

You can access a singleton reference to the Config class using Config::current().

Get

Upon instantiation, the class will read the configuration from file and create a public attribute for each named configuration setting discovered in the file. This means that getting the value of a setting is as simple as accessing the desired attribute of the Config class, e.g. Config::current()->name. Note that modifying an attribute directly will not result in a permanent change to the modified value; use the set() method instead.

Set

Use the set() method to add a new setting to the configuration file or update the value of a setting. The name can be any non-numeric string, and the value can be any JSON-encodable data, e.g. Config::current()->set("name", "My Site"). The method will return true for success and false for failure.

Remove

Use the remove() method to permanently remove a setting from the configuration file, e.g. Config::current()->remove("name"). The method will return true for success and false for failure.