0

I need your help to figure out why my form isn't loading in the Admin Panel.

I currently just get the error:

Fatal error: Call to a member function setData() on a non-object in /home/makeyou/public_html/app/code/core/Mage/Adminhtml/Block/Widget/Form/Container.php on line 129.

Here is my current code: in app/code/local/Sean/MasterCreate/etc/adminhtml.xml

<?xml version="1.0"?>
<!DOCTYPE config>

<config>
    <menu>
        <example translate="title" module="mastercreate">
            <title>MasterCreate</title>
            <sort_order>89</sort_order>
            <action>adminhtml/Creation</action>
        </example>
    </menu>
</config>

For those of you unfamiliar with this code, it creates a new navigation panel in the admin panel that looks for the controller I named Create and runs the index function inside. Here is an image:

enter image description here

app/code/local/Sean/MasterCreate/etc/config.xml

<?xml version="1.0"?>
<!DOCTYPE config>

<config>
    <modules>
        <Sean_MasterCreate>
            <version>0.0.0</version>
        </Sean_MasterCreate>
    </modules>
    <global>
        <models>
            <mastercreate>
                <class>Sean_MasterCreate_Model</class>
            </mastercreate>
        </models>
        <blocks>
            <mastercreate>
                <class>Sean_MasterCreate_Block</class>
            </mastercreate>
        </blocks>
        <helpers>
            <mastercreate>
                <class>Sean_MasterCreate_Helper</class>
            </mastercreate>
        </helpers>
    </global>
    <admin>
        <routers>
            <adminhtml>
                <args>
                    <modules>
                        <mastercreate before="Mage_Adminhtml">Sean_MasterCreate_Adminhtml</mastercreate>
                    </modules>
                </args>
            </adminhtml>
        </routers>
    </admin>
    <frontend>
        <routers>
            <mastercreate>
                <use>standard</use>
                <args>
                    <frontName>mastercreate</frontName>
                    <module>Sean_MasterCreate</module>
                </args>
            </mastercreate>
        </routers>
        <layout>
            <updates>
                <mastercreate>
                    <file>mastercreate.xml</file>
                </mastercreate>
            </updates>
        </layout>
    </frontend>
</config>

app/code/local/Sean/MasterCreate/controllers/Adminhtml/CreationController.php

<?php

class Sean_MasterCreate_Adminhtml_CreationController extends Mage_Adminhtml_Controller_Action {
    public function indexAction(){
        $this->loadLayout();

        $this->_addContent(
            $this->getLayout()->createBlock('mastercreate/adminhtml_event_edit')
        );

        $this->renderLayout();
    }
}

app/code/local/Sean/MasterCreate/Block/Adminhtml/Event/Edit.php

<?php

class Sean_MasterCreate_Block_Adminhtml_Event_Edit extends Mage_Adminhtml_Block_Widget_form_Container {

    public function __construct(){

        $this->_objectId = 'event_id';
        $this->_blockGroup = 'mastercreate';
        $this->_controller = 'adminhtml_creation';

        parent::__construct();

    }

    public function getHeaderText(){
        return Mage::helper('mastercreate')->__('New Event');
    }

}

app/code/local/Sean/MasterCreate/Block/Adminhtml/Event/Edit/Form.php

<?php

class Sean_MasterCreate_Block_Adminhtml_Event_Edit_Form extends Mage_Adminhtml_Block_Widget_Form {

    protected function _prepareForm(){
        $form = new Varien_Data_Form(
            array('id' => 'edit_form', 'action' => $this->getUrl('*/*/save'), 'method' => 'post'
            )
        );

        $fieldset = $form->addFieldset('base_fieldset', array('legend' => Mage::helper('mastercreate')->__('General Information'), 'class' => 'fieldset-wide'));

        $fieldset->addField('name', 'text', array(
            'name' => 'name',
            'label' => Mage::helper('mastercreate')->__('Event Name'),
            'title' => Mage::helper('mastercreate')->__('Event Name'),
            'required' => true
        ));

        $form->setUseContainer(true);
        $this->setForm($form);

        return parent::_prepareForm();

    }

}
1

I found that in my app/code/local/Sean/MasterCreate/Block/Adminhtml/Event/Edit.php

I had to change

public function __construct(){

        $this->_objectId = 'event_id';
        $this->_blockGroup = 'mastercreate';
        $this->_controller = 'adminhtml_creation';

        parent::__construct();

    }

To this:

public function __construct(){

        $this->_objectId = 'event_id';
        $this->_blockGroup = 'mastercreate';
        $this->_controller = 'adminhtml_event';
        $this->_mode = 'edit';

        parent::__construct();

    }

After taking a closer look at how Magento's __construct works it concats blockGroup then controller so in this case the path had to be /mastercreate/adminhtml/event.

Hopefully this helps anyone else with this issue.

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.