2
votes

I'm beginner in PHP and developing my own component for Joomla. I've replaced all the classes in HelloWorld example but yet I haven't change the names of views. If I try to open the specific message/record in the backend I get the error:

Fatal error: Call to a member function getFieldset() on a non-object in administrator/components/com_mycom/views/helloworld/tmpl/edit.php on line 12

Line 12: <?php foreach ($this->form->getFieldset('details') as $field) : ?>

The code of my administrator/components/com_mycom/models/fields/mycom.php:

<?php
defined('_JEXEC') or die;
jimport('joomla.form.helper');
JFormHelper::loadFieldClass('list');

class JFormFieldHelloWorld extends JFormFieldList
{
    protected $type = 'Mycom';
    protected function getOptions()
    {
        $db = JFactory::getDBO();
        $query = $db->getQuery(true);
        $query->select('h.id, h.header, h.parent')
            ->from('#__pages as h')
            ->select('c.title as category')
            ->leftJoin('#__categories AS c ON c.id = h.parent');
        $db->setQuery($query);
        $messages = $db->loadObjectList();
        $options = array();
        if ($messages)
        {
            foreach ($messages as $message)
            {
                $options[] = JHtml::_('select.option', $message->id,
                    $message->header . ($message->parent ? ' (' . $message->category . ')' : '')
                );
            }
        }
        $options = array_merge(parent::getOptions(), $options);
        return $options;
    }
}

Joomla 3.4

2

2 Answers

1
votes

There must be administrator/components/com_mycom/models/fields/helloworld.php as model/view for single record

1
votes

When creating a form, form fields are specified in an XML file in models/forms/helloworld.xml form fields are specified in a fieldset. To get the form fields in view page, we can use any one of the following method.

$this->form = $this->get('Form'); // use in view.html.php file where we store data to be used in view file (edit.php)

in the model file of helloworld.php define the function

public function getForm($data = array(), $loadData = true) {
    // Initialise variables.
    $app = JFactory::getApplication();

    // Get the form.
    $form = $this->loadForm('com_helloworld.helloworld', 'helloworld', array('control' => 'jform', 'load_data' => $loadData));


    if (empty($form)) {
        return false;
    }

    return $form;
}

in the view edit.php file

<?php echo $this->form->getLabel('name'); ?> // label name
<?php echo $this->form->getInput('name'); ?> // input text fields

The other method is

$fieldset = $this->form->getFieldset('fieldset_name'); // name of the fieldset in xml file.

this returns an array.

https://docs.joomla.org/API16:JForm/getFieldset