Joomla 2.5在config.xml中获取组件配置总是返回null [英] Joomla 2.5 get component configuration in config.xml ALWAYS return null

查看:82
本文介绍了Joomla 2.5在config.xml中获取组件配置总是返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助我

我正在创建一个组件.我的组件中有一个config.xml 我写我的自定义JFormFieldUserCheck 在userCheck.php中,我想从config.xml加载参数或字段

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

我用过

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

Resul是

object(stdClass)#214 (0) { }

但是当我将com_my-component更改为com_content(Joomla默认组件)时. 然后使用var_dump,结果很好.

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

预先感谢

推荐答案

我已添加了博客条目的摘录:

插件内部的插件参数

$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 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'); 

模板内部的模板参数

$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'); 

Joomla框架之外的包含文件中的模板参数

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

这篇关于Joomla 2.5在config.xml中获取组件配置总是返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆