$booContext = $modx->getObject('modContext','boo');
$booSiteStartId = $booContext->getOption('site_start');
<?php
//Get Option Attempt 1 - Fails
$c = $modx->newQuery('modContext');
$contextObjects = $modx->getCollection('modContext',$c);
foreach($contextObjects as $contextObject) {
echo $contextObject->get('key') . '<br />';
echo $contextObject->getOption('site_name') . '<br /><br />';
}
<?php
$c = $modx->newQuery('modContextSetting');
$modContextSettings = $modx->getCollection('modContextSetting',$c);
foreach($modContextSettings as $modContextSetting) {
echo $modContextSetting->getOption('site_name') . '<br /><br />';
}
?>
<?php
$modx->switchContext($context);
$siteStart = $modx->getOption('site_start');
?><?php
$object = $modx->getObject('modContextSetting', array('context' => $context, 'key' = 'site_start'));
if ($object) $siteStart = $object->get('value');
?>
<?php
$contexts = array();
$c = $modx->newQuery('modContext');
$c->innerJoin('modContextSetting', 'ContextSettings');
$c->where(array(
'ContextSettings.key' => 'site_type'
,'ContextSettings.value' => 'chapter_subdomain'
));
$contextObjects = $modx->getCollection('modContext',$c);
foreach($contextObjects as $contextObject) {
$currentContext = $contextObject->get('key');
$currentContextSettings = $modx->getCollection('modContextSetting', array('context_key' => $currentContext));
foreach($currentContextSettings as $currentContextSetting) {
$currentContextKey = $currentContextSetting->get('key');
$contexts[$currentContext][$currentContextKey] = $currentContextSetting->get('value');
}
}
foreach($contexts as $key => $context) {
echo $key . "\n";
echo $context['site_url'] . "\n\n";
}
?>
$modx->getOption('setting_name')However, note the caution, "Beware though, this means you are loading the Context’s settings and entire Resource map into memory." My understanding of this caution is that this approach would be much more processor intensive, presumably causing the script to take longer to run. In my case, as our organization grows I may be looping through as many as 50 contexts so the extra time could add up.
<?php $modx->switchContext($context); $siteStart = $modx->getOption('site_start'); ?>
Beware though, this means you are loading the Context’s settings and entire Resource map into memory.
<?php $value = $modx->getContextOption($context, $key); ?>
If you just want to get a modContextSetting instance directly, you would do:
<!php $object = $modx->getObject('modContextSetting', array('context' => $context, 'key' = 'site_start')); if ($object) $siteStart = $object->get('value'); ?>
<!php
$object = $modx->getObject('modContextSetting', array('context_key' => $context, 'key' = 'site_start'));
if ($object) $siteStart = $object->get('value');
?>