2

I am facing some strange issue. I have the similar setup for my component on both front-end and back-end component. Here is my view class signature.

MyComponentViewForm extends JViewLegacy

Now in my view.html.php, I var_dump $this->getForm(),

  • Works fine and dumps the object from the admin component view class
  • Fatal error: Call to undefined method error in front-end view class.

Any ideas?

  • Can you add the full error message with the method and variable info? – David Fritsch Sep 6 '15 at 18:09
1

it not because the problem in your View. You need make sure that your Model extend the JModelForm (or JModelAdmin) and implement method getForm:

YourComponentModelForm extends JModelForm
{
    public function getForm($data = array(), $loadData = true)
    {
        $form = $this->loadForm('com_yourcomponent.formname', 'formname', array('control' => 'jform', 'load_data' => $loadData));
        if (empty($form))
        {
           return false;
        }
        return $form;
    }
}
  • My model extends from JModelAdmin. So that shouldn't be the issue. Infact the JViewLegacy itself has getForm method, so I am wondering how that is not being found on front-end. – Nagarjun Sep 6 '15 at 11:20
  • make sure you have front-end model also – Fedik Sep 6 '15 at 14:36
0

I am not sure how much this is correct but I solved this issue by adding a proxy method in my view.html.php:

public function getForm()
{
    if (!is_object($this->form))
    {
        $this->form = $this->get('Form');
    }

    return $this->form;
}

I am not sure why the view class is calling getForm method of view instead of model. This is still an unknown question to me. Strange part is $this->get('Form') inside this proxy method again invoke method in the model. If anyone has any better solution please let me know, I hate these hacks.

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.