How to change the component parameters in Joomla 3 in code?

  • (0 votes)
  • Written by 
  • Thursday, 28 April 2016 19:34
<?php
// получаем параметры компонента com_users
$params = JComponentHelper::getParams('com_users');
// устанавливаем требуемое значение
$params->set('guest_usergroup', '1');
 
// записываем измененные параметры в БД
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->update($db->quoteName('#__extensions'));
$query->set($db->quoteName('params') . '= ' . $db->quote((string)$params));
$query->where($db->quoteName('element') . ' = ' . $db->quote('com_users'));
$query->where($db->quoteName('type') . ' = ' . $db->quote('component'));
$db->setQuery($query);
$db->execute();
?>

In this example, it is important to pay attention to the reduction of the variable $params to string. As a result of this reduction JRegistry object it will be converted into JSON format and you want to record in the field params #__extensions table.

464 Read