harkor
harkor

Reputation: 503

Get component parameters return empty value on joomla 3.4.1

I have in my component in admin section my "config.xml", the config inputs are ok on the administration of Joomla.

I have for example a field with "my_custom_test" and I set a value, for example "test". I click on "save" button.

If I'm in a view and I want to get my value I'm writing that

$compo_params = JComponentHelper::getParams('com_xxxxx');
var_dump($compo_params).'<br />';
echo $compo_params->get('my_custom_test', 'EMPTY');

The result is that

object(Joomla\Registry\Registry)#19 (2) { ["data":protected]=> object(stdClass)#20 (1) { ["params"]=> object(stdClass)#57 (1) { ["my_custom_test"]=> string(4) "test" } } ["separator"]=> string(1) "." }
EMPTY

The result is "EMPTY" instead of "test".

Do you have any idea ?

Upvotes: 1

Views: 1064

Answers (2)

Fiona Coulter
Fiona Coulter

Reputation: 66

Actually I have found the source of the problem, it is in the component config.xml file. If you have the parameters enclosed in a tag (which was the standard practice for Joomla in the past), then the parameters are stored inside an object called "params", eg

<?xml version="1.0" encoding="utf-8"?>
<config>
<fields name="params" label="Some label">
<fieldset name="basic" label="Basic Options" description="">
     <field name="some_option" label="label" type="text" description="" />
</fieldset>
</fields>
</config>

To correct the problem, just leave out the tag:-

<?xml version="1.0" encoding="utf-8"?>
<config>
<fieldset name="basic" label="Basic Options" description="">
     <field name="some_option" label="label" type="text" description="" />
</fieldset>
</config>

If you look at any of the core Joomla component config.xml files this is how they do it now.

Then the standard method of getting the component params works:-

$compo_params = JComponentHelper::getParams('com_xxxxx');
$my_custom_test = $compo_params->get('my_custom_test', '');

Upvotes: 3

harkor
harkor

Reputation: 503

The solution is

echo $compo_params->get('params')->my_custom_test;

Upvotes: 0

Related Questions