Joomla 2.5 get component configuration in config.xml ALWAYS return null

。_饼干妹妹 提交于 2019-12-24 08:57:12

问题


Please help me with this

I am creating a component. There is a config.xml in my component I write my custom JFormFieldUserCheck in userCheck.php I want to load parameter or field from config.xml

I used

$param = JComponentHelper::getParams('com_my-component');
var_dump($param);

Resul is

object(stdClass)#214 (0) { }

But when I change com_my-component to com_content (Joomla default component). then var_dump, result is fine.

Thanks in advance


回答1:


I have added an excerpt from the blog entry:

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']; 



回答2:


Clearly, Joomla isn't understanding your component. Insure that it's properly installed in Joomla, and that the xml file for the component is accurate and formed properly. If Joomla does find your component, or is unable to load the XML, then the parameters cannot be made available to your PHP. These steps are done with the valid entries in the database, and the XML, both of which are typically done with the component installation, but can be done manually as long as you get them all correct.




回答3:


Had the same problem. The result was empty until i went to the configuration of my component and saved it (though there were default values printed in the textfields).



来源:https://stackoverflow.com/questions/11770837/joomla-2-5-get-component-configuration-in-config-xml-always-return-null

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!