If you use client config in a multi context senario e.g.
In Client conf I have this setup with multi contexts
DEFAULT
SomeValueInConfig = Value X
CONTEXT1
SomeValueInConfig = Value X
CONTEXT1
SomeValueInConfig = Value Y
CONTEXT1
[[++SomeValueInConfig]]
Shows correct Value X
CONTEXT2
[[++SomeValueInConfig]]
Shows iincorrect Value X
This does not always happen sometimes if you clear the cache it shows value “Value Y” in CONTEXT2, however most oof the time I get the wrong value.
Could it be that it pulls client config before it knows what context it is in?
how do I make sure it context loads before? I set onMODXinit in the ClientConfig plugin to a lower priority than the contextRouter. does not seem to make a difference though.
<?php
/**
* ClientConfig
*
* Copyright 2011-2014 by Mark Hamstra <hello@markhamstra.com>
*
* ClientConfig is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* ClientConfig is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* ClientConfig; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA
*
* @package clientconfig
*
* @var modX $modx
* @var int $id
* @var string $mode
* @var modResource $resource
* @var modTemplate $template
* @var modTemplateVar $tv
* @var modChunk $chunk
* @var modSnippet $snippet
* @var modPlugin $plugin
*/
$eventName = $modx->event->name;
switch($eventName) {
case 'OnMODXInit':
case 'OnHandleRequest':
case 'pdoToolsOnFenomInit':
/* Grab the class */
$path = $modx->getOption('clientconfig.core_path', null, $modx->getOption('core_path') . 'components/clientconfig/');
$path .= 'model/clientconfig/';
$clientConfig = $modx->getService('clientconfig','ClientConfig', $path);
/* If we got the class (gotta be careful of failed migrations), grab settings and go! */
if ($clientConfig instanceof ClientConfig) {
$contextKey = $modx->context instanceof modContext ? $modx->context->get('key') : 'web';
$settings = $clientConfig->getSettings($contextKey);
/* Make settings available as [[++tags]] */
$modx->setPlaceholders($settings, '+');
/* Make settings available for $modx->getOption() */
foreach ($settings as $key => $value) {
$modx->setOption($key, $value);
}
}
break;
}
return;
Plugin code for CLient Config all seems fine. Maybe it does not know what context it is in when it calls
Maybe try logging some information in the plugins to debug the issue.
Add a line like this to the ClientConfig plugin and something similar to ContextRouter plugin.
it says it routing to context2 but it is still in web context which means clientConfig it will read the web contect instead of context 2 and display the wrong variable.
is there another way to get the key? instead of
$contextKey = $modx->context instanceof modContext ? $modx->context->get(‘key’) : ‘web’;
which does not seem to get the right context? Or am I completly off?
This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.