getOption
Last updated Dec 21st, 2019 | Page history | Improve this page | Report an issue
Support the team building MODX with a monthly donation.
The budget raised through OpenCollective is transparent, including payouts, and any contributor can apply to be paid for their work on MODX.
Backers
Budget
$311 per month—let's make that $500!
Learn morexPDOObject::getOption()¶
Get an option value for this instance of an xPDOObject, using xPDO options if no instance specific option exists.
Syntax¶
API Docs: http://api.modxcms.com/xpdo/om/xPDOObject.html#getOption
mixed getOption (string $key [, array|null $options [, mixed $default [, boolean $skipEmpty]]] )
-
$key
: the key of the setting or option to load. -
$options
: the source of the setting or option. Either null (which attempts to find the key in the main configuration) or an array of options. -
$default
: the value to return when the key was not found. -
$skipEmpty
: when set to true, the $default will also be returned if the $key's value is an empty string. Added in xPDO 2.2.1 / MODX 2.2.0-rc2.
Examples¶
Simple Option Retrieval¶
Gets the config setting for xPDO::OPT_HYDRATE_FIELDS.
$hydrateFields = $xpdo->getOption(xPDO::OPT_HYDRATE_FIELDS);
Gets the config option for 'test', and if not set, returns '123'.
$test = $xpdo->getOption('test',null,'123');
Checks the $props array for the key 'depth', and if doesn't exist, then checks $xpdo->config, and if still doesn't exist, then sets to 10.
$props = array();
$depth = $xpdo->getOption('depth',$props,10);
echo $depth; // prints 10
$xpdo->setOption('depth',20);
$depth = $xpdo->getOption('depth',$props,10);
echo $depth; // prints 20
$props['depth'] = 30;
$depth = $xpdo->getOption('depth',$props,10);
echo $depth; // prints 30
Support the team building MODX with a monthly donation.
The budget raised through OpenCollective is transparent, including payouts, and any contributor can apply to be paid for their work on MODX.
Backers
Budget
$311 per month—let's make that $500!
Learn more