Jump to main content Jump to doc navigation

xPDOObject::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

  • modmore
  • STERC
  • Digital Penguin
  • Jens Wittmann – Gestaltung & Entwicklung
  • Fabian Christen
  • Dannevang Digital
  • Sepia River Studios
  • CrewMark
  • Chris Fickling
  • deJaya
  • eydolan
  • Following Sea
  • Lefthandmedia
  • Murray Wood
  • Anton Tarasov
  • Stéphane Jäggi
  • Raffy
  • Snow Creative
  • A. Moreno
  • Nick Clark
  • JT Skaggs
  • Helen
  • YJ
  • krisznet
  • Richard
  • Yanni

Budget

$311 per month—let's make that $500!

Learn more