2012-08-02 32 views
1

請幫我這個Joomla 2.5在config.xml中獲取組件配置ALWAYS返回null

我正在創建一個組件。有一個在我的組件 一個config.xml中我寫我的自定義JFormFieldUserCheck 在userCheck.php我想從config.xml中

我用

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

Resul負載參數或字段

object(stdClass)#214 (0) { } 

但是,當我將com_my-component更改爲com_content(Joomla默認組件)時。 然後var_dump,結果很好。

在此先感謝

回答

14

我已經加入從博客條目的摘錄:從插件內部

插件參數從一個插件外從內側

$plugin = &JPluginHelper::getPlugin('exampleType', 'example'); 
$pluginParams = new JParameter($plugin->params); 
$param = $pluginParams->get('paramName', 'defaultValue'); 

模塊參數

$param = $this->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']; 
1

顯然,Joomla並不理解您的組件。確保它在Joomla中正確安裝,並且組件的xml文件是準確的並且正確地形成。如果Joomla確實找到了你的組件,或者無法加載XML,那麼這些參數就無法提供給你的PHP。這些步驟是通過數據庫中的有效條目和XML完成的,這兩個步驟通常都是通過組件安裝完成的,但只要您完全正確地完成,就可以手動完成。

0

外面有同樣的問題。結果是空的,直到我去配置我的組件並保存它(儘管有默認值打印在文本字段中)。