简体   繁体   中英

joomla get and set configurations for a component

For sometime I have been trying to create a simple admin form to use to save configurations and a way to access these configs from the site side without necessarily going to the database. I just can't seem to understand how this documentation can help me achieve this. This link sheds some light on how to get the saved configurations but I am stuck on how and where to save the configs.

I am using joomla 2.5

It is a component i am trying to develop. On the site side of the application I have a method to get the configuration as:

//We add config code.
$componentParams = &JComponentHelper::getParams('com_rocket');
$param = $componentParams->get('speed', 'null'); 

This I believe will work fine however I have no idea how to save the configuration somewhere and have a way to edit it as well.

Thanks for your effort.

To get component parameters for Joomla 2.5, try using the following:

$app = JFactory::getApplication('site');
$componentParams = $app->getParams('com_rocket');
$param = $componentParams->get('speed', null);

// Display the result
echo $param;

And to set the component parameter, try this:

$value = "some value here";
$param->set('speed', $value);

$db = JFactory::getDbo();
$query = $db->getQuery(true);

$query->update($db->quoteName('#__extensions') . ' AS a')
      ->set('a.params = ' . $db->quote((string)$param))
      ->where('a.element = "com_rocket"');

$db->setQuery($query);
$db->query();

Just for completeness sake. I finally managed to get how I could do it in a simpler manner. To manage the configurations for a component all I needed to do was:

  1. Create a config class in the admin folder

     <field name="speed" type="text" label="COM_ROCKET_CONFIG_FIELD_SPEED_LABEL" description="COM_ROCKET_CONFIG_FIELD_SPEED_DESC" default="200" /> </fieldset> 

  1. In the view class I added the code below

     protected function addToolBar() { JToolBarHelper::title('settings'); JToolBarHelper::preferences('com_rocket'); } 
  2. in the display method I added a call to the above toolbar method

      // Set the toolbar $this->addToolBar(); 

and whallaa everything was taken care of.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM