【问题标题】:Joomla 2.5 get component configuration in config.xml ALWAYS return nullJoomla 2.5 在 config.xml 中获取组件配置总是返回 null
【发布时间】:2012-08-02 03:54:53
【问题描述】:

请帮我解决这个问题

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

我用过

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

结果是

object(stdClass)#214 (0) { }

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

提前致谢

【问题讨论】:

    标签: php joomla


    【解决方案1】:

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

    插件内部的插件参数

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

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

    // 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】:

      显然,Joomla 不了解您的组件。确保它在 Joomla 中正确安装,并且组件的 xml 文件准确且格式正确。如果 Joomla 确实找到了您的组件,或者无法加载 XML,那么这些参数将无法用于您的 PHP。这些步骤是使用数据库中的有效条目和 XML 完成的,这两者通常都是通过组件安装完成的,但只要您全部正确,就可以手动完成。

      【讨论】:

        【解决方案3】:

        遇到了同样的问题。结果是空的,直到我去配置我的组件并保存它(尽管在文本字段中打印了默认值)。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2020-10-17
          • 2010-11-05
          • 1970-01-01
          • 2014-03-08
          • 1970-01-01
          • 1970-01-01
          • 2013-10-29
          • 1970-01-01
          相关资源
          最近更新 更多