Created
March 30, 2014 20:23
-
-
Save cmpscabral/9879190 to your computer and use it in GitHub Desktop.
joomla component/module/plugin parameters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Plugin parameters from inside a plugin | |
$param = $this->params->get('paramName', 'defaultValue'); | |
Plugin parameters from outside a plugin | |
$plugin = &JPluginHelper::getPlugin('exampleType', 'example'); | |
$pluginParams = new JParameter($plugin->params); | |
$param = $pluginParams->get('paramName', 'defaultValue'); | |
Module parameters from inside a module | |
$param = $params->get('paramName', 'defaultValue'); | |
Module parameters from outside a module | |
$module = &JModuleHelper::getModule('example'); | |
$moduleParams = new JParameter($module->params); | |
$param = $moduleParams->get('paramName', 'defaultValue'); | |
Component parameters from inside a component | |
$componentParams = &JComponentHelper::getParams('com_example'); | |
$param = $componentParams->get('paramName', 'defaultValue'); | |
Component parameters from outside a component | |
$componentParams = &JComponentHelper::getParams('com_example'); | |
$param = $componentParams->get('paramName', 'defaultValue'); | |
Template parameters from inside a template | |
$param = $this->params->get('paramName'); | |
Template parameters from outside a template | |
jimport('joomla.filesystem.file'); | |
$mainframe = &JFactory::getApplication(); | |
$params = $mainframe->getParams(JFile::read(JURI::root() .'/templates/template_name/params.ini')); | |
$param = $params->get('paramName', 'defaultValue'); | |
Template parameters from an included file outside the Joomla framework | |
// 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']; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment