Hey,
I needed a script that would list all contexts (without the mgr) from which I could load particular settings and tho there were lot's topics on the forum 'like this' none of them fitted my purpose, this it what I came up with. The results can be used in e.g. the index.php to return all contexts and initialise the requested.
<?php
require_once 'config.core.php';
require_once MODX_CORE_PATH.'model/modx/modx.class.php';
$modx = new modX();
$modx->getService('error','error.modError', '', '');
/* script starts here */
$contextKeys = array();
$query = $modx->newQuery('modContext', array('key:NOT IN' => array('mgr')));
$query->select($modx->getSelectColumns('modContext', 'modContext', '', array('key')));
if ($query->prepare() && $query->stmt->execute()) {
$contextKeys = $query->stmt->fetchAll(PDO::FETCH_COLUMN);
}
foreach($contextKeys as $key=>$value)
{
$contextInit = $modx->getContext($value);
$contextKey = $value;
$contextSettings = $contextInit->config;
echo $contextKey . "</br>";
echo $contextSettings['site_url'] . '</br>';
echo $contextSettings['site_start'] . '</br><hr>';
}
?>
Result will be something like:
patbloomcom
http://patbloom.com/
154
----------------------------
vamdsnl
http://vamds.nl/
21
----------------------------
web
http://vamds.com/
1
----------------------------
Still working on getting the 'context name' - suggestions are welcome
Pat