Since the release of Joomla 1.5, developers can enable users to configure extensions using parameters. While the possibility of being able to do this is great, it is often a chore to keep track of the code needed to access one of these parameters. Therefor, in this blog I will present an overview of the code needed to access all the different parameters.

Image credits: Edwin Young
$param = $this->params->get('paramName', 'defaultValue');
$plugin = &JPluginHelper::getPlugin('exampleType', 'example');
$pluginParams = new JParameter($plugin->params);
$param = $pluginParams->get('paramName', 'defaultValue');
$param = $params->get('paramName', 'defaultValue');
$module = &JModuleHelper::getModule('example');
$moduleParams = new JParameter($module->params);
$param = $moduleParams->get('paramName', 'defaultValue');
$componentParams = &JComponentHelper::getParams('com_example');
$param = $componentParams->get('paramName', 'defaultValue');
$componentParams = &JComponentHelper::getParams('com_example');
$param = $componentParams->get('paramName', 'defaultValue');
$param = $this->params->get('paramName');
jimport('joomla.filesystem.file');
$mainframe = &JFactory::getApplication();
$params = $mainframe->getParams(JFile::read(JURI::root() .'/templates/template_name/params.ini'));
$param = $params->get('paramName', 'defaultValue');
// Get params.ini relative to the current file location (use your own relative path here)
$paramsFile = dirname(__FILE__) . '/../../params.ini';
// Only continue if the file exists
if(file_exists($paramsFile)) {
// Get contents from params.ini file
$iniString = file_get_contents($paramsFile);
// Escape double quotes in values and then double-quote all values (because Joomla doesn't do that for us..)
$iniQuoted = preg_replace('/=(.*)\\n/', "=\"$1\"\n", addcslashes($iniString, '"'));
// Parse the ini string to an associative array
$iniParsed = parse_ini_string($iniQuoted);
} else {
$iniParsed = '';
}
// Set params to obtained values or empty array
$params = (!empty($iniParsed)) ? $iniParsed : array();
// Get param value from array
$param = $params['paramName'];
Buy 2 Templates, Get Your Third Free!
By popular demand we've introduced a way to purchase multiple templates, at a discounted rate! If you add any three templates to your shopping cart, you'll only have to pay for two!
Upcoming conferences
Past conferences
0 items
View cart
thanks for very good blog