0

I'm building a Joomla-component (as an example I use com_weblinks) and in the category view I want to have extra fields, e.g. a field for choosing from several layout themes. In default.xml I've added extra fields/fieldset.

<fields name="extrafields">
        <fieldset name="extrafields">
           <field 
               name="theme"

When I'm trying to call this param in default_items.php with e.g.

$theme = $this->extrafields->get('theme');

I get an error on frontend 'Call to a member function get() on null'

When I place the extra field under the params fields

<fields name="params">
        <fieldset name="basic" label="JGLOBAL_CATEGORY_OPTIONS">
            <field 
                name="theme"

And then calling this param with e.g.

 $theme = $this->params->get('theme');
 echo $theme;

The name of the chosen theme is correctly displayed.

I can't figure out what I'm doing wrong. Have I missed something? Do I have to put extra code in view.html.php?

0

The error occurs because you do not have any code for saving and retrieving your field data. $this->extrafields is undefined.

How to solve this depends on how and where you want to store your data. If you have no preference and just want the fields to have their own tab in the form, keep using params field group but use a custom fieldset:

<fields name="params">
    <fieldset name="extrafields">
        <field 
            name="theme"

This way your fields are stored along with params and are accessible the same way:

$this->params->get('theme');
  • Thx. This works. The other option I will look into some other time. – Franky Dec 19 '18 at 16:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.