-
Notifications
You must be signed in to change notification settings - Fork 0
Component Parameters Service
Every Joomla! Component has the possibility to easily add configuration parameters through a config.xml file placed in the root of the components administrator folder (/administrator/components/com_foobar).
This automatically provides the developer with an "options" button in his component's backend that renders various types of configuration fields. This service makes it easier to access and store these parameters from anywhere in your code.
To read the parameters values from within your component, just call the service through your container:
$yourParam = $this->container->params->get('paramName', 'defaultValue');
The parameters are loaded from the database when the service is initialize for the first time. If later on in your component's workflow these parameters change, you can reload them from the database using the method reload()
:
$this->container->params->reload();
You can also change the parameters value from anywhere in your code. To set the new values, just call
$this->container->params->set('paramName', 'newValue');
You can also set multiple values at the same time.
$this->container->params->set(array('newParam1' => 'newValue1', 'newParam2' => 'newValue2'));
After you've set your parameters new values, you can persist them to the database by calling
$this->container->params->save();
Note: if you don't do this, the new values will NOT be actually saved.
FOF (Framework on Framework) and its documentation are Copyright © 2010-2020 Nicholas K. Dionysopoulos / Akeeba Ltd.
FOF is Open Source Software, distributed under the GNU General Public License, version 2 of the license, or (at your option) any later version.
The FOF Wiki content is provided under the GNU Free Documentation License, version 1.3 of the license, or (at your option) any later version.
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license can be found on the GNU site.