Option
Click here if you want to read this article for the latest version.
Piwik\
Option
Convenient key-value storage for user specified options and temporary data that needs to be persisted beyond one request.
Examples
Setting and getting options
$optionValue = Option::get('MyPlugin.MyOptionName');
if ($optionValue === false) {
// if not set, set it
Option::set('MyPlugin.MyOptionName', 'my option value');
}
Storing user specific options
$userName = // ...
Option::set('MyPlugin.MyOptionName.' . $userName, 'my option value');
Clearing user specific options
Option::deleteLike('MyPlugin.MyOptionName.%');
Methods
The class defines the following methods:
get()— Returns the option value for the requested option$name.getLike()— Returns option values for options whose names are like a given pattern.set()— Sets an option value by name.delete()— Deletes an option.deleteLike()— Deletes all options that match the supplied pattern.clearCachedOption()
get()
Returns the option value for the requested option $name.
Signature
It accepts the following parameter(s):
$name(string) — The option name.
Returns:
string|false— The value orfalse, if not found.
getLike()
Returns option values for options whose names are like a given pattern. Only % is supported as part of the
pattern.
Signature
It accepts the following parameter(s):
$namePattern(string) — The pattern used in the SQLLIKEexpression used to SELECT options.'%'characters should be used as wildcard. Underscore match is not supported.
Returns:
array— Array mapping option names with option values.
set()
Sets an option value by name.
Signature
It accepts the following parameter(s):
$name$value$autoload
It does not return anything or a mixed result.
delete()
Deletes an option.
Signature
- It accepts the following parameter(s):
$name(string) — Option name to match exactly.$value(string) — If supplied the option will be deleted only if its value matches this value.
- It does not return anything or a mixed result.
deleteLike()
Deletes all options that match the supplied pattern. Only % is supported as part of the
pattern.
Signature
- It accepts the following parameter(s):
$namePattern(string) — Pattern of key to match.'%'characters should be used as wildcard. Underscore match is not supported.$value(string) — If supplied, options will be deleted only if their value matches this value.
- It does not return anything or a mixed result.
clearCachedOption()
Signature
It accepts the following parameter(s):
$name
It does not return anything or a mixed result.