Legacy Documentation
You are using the documentation for version 4.3.8. Go here for the latest version.
Config Service¶
Simple Example¶
This service will read items from a config file. By default all add-ons have a
config directory located at ./config/ relative to their addon.setup.php file.
To fetch items from your config simply do:
ee('Config')->get('my_addon:my_config.my_item');
Note
This does not replace ee()->config
Config Service Methods¶
-
class
EllisLab\\ExpressionEngine\\Service\\Config\Factory¶
-
EllisLab\\ExpressionEngine\\Service\\Config\Factory::getDirectory($path)¶ Get a config directory
Parameters: - $path (string) – The path to the directory
Returns: The directory
Return type: Directory
-
EllisLab\\ExpressionEngine\\Service\\Config\Factory::getFile($name = 'config')¶ Get a config file
Parameters: - $name (string) – Config file name, optionally with a provider prefix
Returns: The config file
Return type: File
-
EllisLab\\ExpressionEngine\\Service\\Config\Factory::get($item, $default = NULL)¶ Get a config item
Parameters: - $name (string) – Config item name, optionally with a provider prefix
- $default (mixed) – The value to return if $path can not be found
Returns: The config item, or
$defaultif it doesn’t existReturn type: Mixed
Directory Object Methods¶
-
class
EllisLab\\ExpressionEngine\\Service\\Config\Directory¶
-
EllisLab\\ExpressionEngine\\Service\\Config\Directory::get($item, $default = NULL)¶ Get a config item from this directory
Parameters: - $default (mixed) – The value to return if $path can not be found
Returns: The config item, or
$defaultif it doesn’t existReturn type: Mixed
-
EllisLab\\ExpressionEngine\\Service\\Config\Directory::hasFile($filename)¶ Check if this directory contains the given config file
Returns: TRUE if it has the file, FALSE if not Return type: Boolean
-
EllisLab\\ExpressionEngine\\Service\\Config\Directory::getFile($filename = 'config')¶ Returns a ConfigFile class representing the config file
Parameters: - $filename (string) – Name of the file
Returns: ConfigFile object
Return type: File
File Objet Methods¶
-
class
EllisLab\\ExpressionEngine\\Service\\Config\File¶
-
EllisLab\\ExpressionEngine\\Service\\Config\File::get($path, $default = NULL)¶ Get an item from the config, you can use “item.subitem.subsubitem” to drill down in the config
Parameters: - $path (string) – The config item to get
- $default (mixed) – The value to return if $path can not be found
Returns: The value found for
$path, or$defaultif it doesn’t existReturn type: Mixed
-
EllisLab\\ExpressionEngine\\Service\\Config\File::has($path)¶ Check if the file has a given item
Returns: TRUE if it has the item, FALSE if not Return type: Boolean
-
EllisLab\\ExpressionEngine\\Service\\Config\File::getBoolean($path, $default = FALSE)¶ Get a config item as a boolean
This is aware of some of EE’s conventions, so it will cast strings y and n to the correct boolean.
Parameters: - $path (string) – The config item to get
- $default (bool) – The default value
Returns: The value cast to bool
Return type: Boolean
-
EllisLab\\ExpressionEngine\\Service\\Config\File::set($path, $value)¶ Set an item in the config. You can use ‘item.subitem.subsubitem’ to drill down in the config.
Parameters: - $path (string) – The config item to set
- $value (mixed) – The value to set
Return type: Void