Answer the question
In order to leave comments, you need to log in
Why does changing the system settings not from under the admin work?
I have a system setting (number). I want this number to increase by 1 on the site when the button is clicked. I created a snippet with the following content:
<?php
$settingName = 'quiz_counter';
$currentCount = $modx->getOption($settingName);
$currentCount++;
$response = $modx->runProcessor(
'system/settings/update',
array(
'key' => $settingName,
'value' => $currentCount,
'namespace' => 'core'
)
);
$modx->reloadConfig();
$('.btn').on('click', function() {
$.ajax({
url: '/system/quiz-counter-increment/',
data: ''
})
});
Answer the question
In order to leave comments, you need to log in
Good afternoon!
Try my snippet. We get and change the system setting as a MODX object.
$settingName = 'quiz_counter';
$currentCountArray = $modx->getObject('modSystemSetting', $settingName);
$currentCount = $currentCountArray->get('value');
$currentCount++;
$currentCountArray->set('value', $currentCount);
$currentCountArray->set('editedon', date("Y-m-d H:i:s")); // Не обязательно, но коли есть такое поле, почему не использовать?
$currentCountArray->save();
$cacheRefreshOptions = array( 'system_settings' => array() );
$modx->cacheManager-> refresh($cacheRefreshOptions);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question