K
K
Karen Kratyan2012-06-18 18:25:04
MODX
Karen Kratyan, 2012-06-18 18:25:04

How to get parameters/settings from all contexts in MODx?

Created a plugin that fires on the "OnHandleRequest" event.
I make a request like this:

$contexts = $modx->getCollection('modContext', array('key:NOT IN' => array('web', 'mgr')));

Checking:
foreach($contexts as $cx) {
$modx->log(modX::LOG_LEVEL_ERROR, $cx->key); 
}

I got all the contexts like, but I get the default parameters:
$cx->getOption('http_host')

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan Klimchuk, 2012-06-18
@kratkar

It is possible to pull all settings directly from the modx_context_setting table.

$cs = $modx->getCollection('modContextSetting');
foreach($cs as $csi){
  print_r($csi->toArray());
}

If conditions are needed, then create a criterion and specify all the conditions in it, then execute a query for a selection.

N
Nikolai Lanets, 2012-09-24
@Fi1osof

To get context settings, you need to “prepare” this context

if($cx->prepare()) {
  print_r($cx->config);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question