Quote from: BobRay at Oct 13, 2008, 03:56 AMJust create context settings to override the system settings. Then each context will be able to determine which options are in effect for captcha_mathstring.
At the least, I ought to re-do the captcha function so it’s easier to override the system setting for using the mathstring -- maybe with a $_POST variable (or setPlaceholder() ). Some users might want to use the mathstring in the Manager login but not elsewhere or vice versa.
You said this earlier.
configuration settings should always be considered read-only, unless you are changing them permanently in the scope of the system, a context, or a user. Changes to settings will potentially affect all users, since context and user settings can inherit values from the previous layer.
What am I missing?
You don’t need to create a context, just add those settings to a context when you want to override the value in the system setting, for existing contexts.
$ctx = $modx->newObject('modContext',"newContext");
$modx->switchContext('newContext');
$ss = $modx->newObject('modSystemSetting');
$ss->set('key','captcha_use_mathstring');
$ss->set('value',false);Do you want to do it in the build, or runtime? If build:
Quote from: OpenGeek at Oct 13, 2008, 01:21 PM
You don’t need to create a context, just add those settings to a context when you want to override the value in the system setting, for existing contexts.
Um . . . how can I add settings to a context that hasn’t been created?
$ctx = $modx->newObject('modContext');
$ctx->set('key','newContext');
$settings[] = array();
$ss = $modx->newObject('modContextSetting');
$ss->set('key','captcha_use_mathstring');
$ss->set('value',false);
$settings[$ss->get('key')] = $ss;
$ctx->addMany($settings);
$builder->createVehicle($ctx,array (
XPDO_TRANSPORT_PRESERVE_KEYS => true,
XPDO_TRANSPORT_UPDATE_OBJECT => true,
XPDO_TRANSPORT_UNIQUE_KEY => 'key',
XPDO_TRANSPORT_RELATED_OBJECTS => true,
XPDO_TRANSPORT_RELATED_OBJECT_ATTRIBUTES => array (
'modContextSetting' => array (
XPDO_TRANSPORT_PRESERVE_KEYS => false,
XPDO_TRANSPORT_UPDATE_OBJECT => true,
XPDO_TRANSPORT_UNIQUE_KEY => array ('context_key', 'key'),
),
),
));
$ctx->set('key','newContext');I guess we’re both lost, though I was there first.
Why would you need to create a context, this is where I’m getting lost. You just need to set the settings for the existing contexts, web, mgr, and connectors, right?

Creating contexts at run-time will be cool for a multi-site setup tool, but I don’t see any valid scenarios for doing this otherwise.
Cool. How about runtime? Is it the same, but without the builder code?
Also, I don’t understand what this is doing or why it’s necessary:
$ctx->set('key','newContext');
No, settings are configuration values that are available to every request to the system, context, and/or a specific user account. They are not meant to be used for temporary settings across requests. This is what a session is for (or one could use messages in modRegistry, but that’s another topic for a later date).
I want to override an existing System Setting (captcha_use_mathstring) at runtime (in a snippet) long enough to have my temporary setting be in effect for the use of <img src="captcha.php">. Captcha.php needs to see my temporary System Setting. I’d like the temporary System setting to go out of scope by the end of the snippet so it won’t affect other snippets. If I could do it without a plugin, that would be a plus.
I thought it might be easy to do with contexts. If not, there are other ways to handle the problem.
I want to override an existing System Setting (captcha_use_mathstring) at runtime (in a snippet) long enough to have my temporary setting be in effect for the use of <img src="captcha.php">. Captcha.php needs to see my temporary System Setting. I’d like the temporary System setting to go out of scope by the end of the snippet so it won’t affect other snippets. If I could do it without a plugin, that would be a plus.
I thought it might be easy to do with contexts. If not, there are other ways to handle the problem.
class Captcha {
var $config;
var $modx;
// php4 compat
function Captcha(&$modx, $config = array()) {
$this->__construct($modx,$config);
}
function __construct(&$modx, $config = array()) {
$this->modx =& $modx;
$config = array_merge($config,array(
'use_mathstring' => false, // here's the override, you can change this
// to whatever, whenever, via $this->config
));
$this->config = $config;
}
function doSomething() {
$um = $this->config['use_mathstring'];
//etc...
return $a_value;
}
}
$captcha = new Captcha($modx,array( 'use_mathstring' => $modx->config['use_mathstring'], )); $result = $captcha->doSomething(); //...