How To Add Configuration Options in Joomla Component

The Joomla framework allows the use of parameters stored in each component. The fields for the configuration options are stored in the XML file located at admin/config.xml.

This file is read by the com_config component of the Joomla core.

<?xml version="1.0" encoding="utf-8"?>
<option value="0">JHIDE</option>
<option value="1">JSHOW</option>

Additionally, you need to put Preferences (Options) button in a toolbar.


How To Get Configuration Values 

You need to get a component params for use at different places in the code. To access component params in component itself, you can use JFactory::getApplication() like below:

$app = JFactory::getApplication();
$params = $app->getParams();
$param = $params->get('show_category');

To access component params from another component, you can use JComponentHelper::getParams() like below:

$content_params = JComponentHelper::getParams( 'com_content' );
$show_date = $content_params->get( 'show_create_date' );

Default Configuration, Item Configuration, Menu Configuration

In Joomla, configuration parameters for extensions can be set at many levels.

  1. The default configuration is stored in admin/config.xml file at the administrator part of the component.

  2. At the menu level, it is stored in default.xml file in the tmpl folder of the front-end view.

  3. Administrator can control the display in the front end by specifying a global configuration parameter or override this setting on an individual item basis. To enable this, you need a params field in the database, which will be a string in JSON format.

Step 1: Change XML form for item to add params field

You need to edit configuration parameters for each item, so you need to change the XML form.


<fields name="params">
<fieldset name="params" label="JGLOBAL_FIELDSET_DISPLAY_OPTIONS">
label="Show Category"
<option value="0">JHIDE</option>
<option value="1">JSHOW</option>

Step 2: Modify table class to handle JSON string

The following function will convert params field to JSON string. You have to overload the bind method to convert the array of the parameters into a JSON string for saving in the database.


public function bind($array, $ignore = '')
if (isset($array['params']) && is_array($array['params']))
// Convert the params field to a string.
$parameter = new JRegistry;
$array['params'] = (string)$parameter;

return parent::bind($array, $ignore);

Step 3: Modify back-end edit layout

The backend edit view has to display the options to the administrator.


<?php echo JHtml::_('bootstrap.addTab', 'myTab', 'options', 'Options'); ?>
<div class="row-fluid form-horizontal-desktop">
<?php echo $this->form->renderFieldset('params'); ?>
<?php echo JHtml::_('bootstrap.endTab'); ?>

Step 4: Modify front end model to merge global parameters and individual parameters

The parameters are stored at two levels - global parameters and individual parameters. First, the global parameters are stored in the state variable in the function populateState(). 


protected function populateState()
// Get the message id
$jinput = JFactory::getApplication()->input;
$id = $jinput->get('id', 1, 'INT');
$this->setState('', $id);

// Load the parameters.
$this->setState('params', JFactory::getApplication()->getParams());

Then, we get the stored params from the database in the getItem() as a JSON string. After that, load the JSON string as array and merge global params with item params.

public function getItem()
if (!isset($this->item))
$id = $this->getState('');
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('h.greeting, h.params, c.title as category')
->from('#__helloworld as h')
->leftJoin('#__categories as c ON')
->where('' . (int)$id);

if ($this->item = $db->loadObject())
// Load the JSON string
$params = new JRegistry;
$params->loadString($this->item->params, 'JSON');
$this->item->params = $params;

// Merge global params with item params
$params = clone $this->getState('params');
$this->item->params = $params;
return $this->item;


Star InactiveStar InactiveStar InactiveStar InactiveStar Inactive