1

I'm starting with magento and following one book have one problem when tray to see my form in frontend. Always send me the error: Call to a member function setData() on a non-object and, the log files says to me "The block is not valid:Mage_Registries_Block_Adminhtml_Giftregistry_Edit_Form"

My code is the next:

File: app/code/local/Mdg/Giftregistry/Block/Registries/Edit/Form.php

class Mdg_Giftregistry_Block_Adminhtml_Registries_Edit_Form extends  Mage_Adminhtml_Block_Widget_Form {         

protected function _prepareForm(){       
    $form = new Varien_Data_Form(array(
        'id' => 'edit_form',
        'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
        'method' => 'post',        
        'enctype' => 'multipart/form-data'         
   ));     
    $form->setUseContainer(true);    
    $this->setForm($form);  

    if (Mage::getSingleton('adminhtml/session')->getFormData()){   
        $data = Mage::getSingleton('adminhtml/session')->getFormData();  
        Mage::getSingleton('adminhtml/session')->setFormData(null);       
   }elseif(Mage::registry('registry_data')){
       $data = Mage::registry('registry_data')->getData();   
   }

   $fieldset = $form->addFieldset('registry_form', array('legend'=>Mage::helper('mdg_giftregistry')->__('Gift Registry information')));         
   $fieldset->addField('type_id', 'text', array('label'=> Mage::helper('mdg_giftregistry')->__('Registry Id'),'class'=> 'required-entry','required'  => true,'name'=> 'type_id',)); 
   $fieldset->addField('website_id', 'text', array('label'=> Mage::helper('mdg_giftregistry')->__('Website Id'),'class'=> 'required-entry','required'=> true,'name'=> 'website_id',));
   $fieldset->addField('event_location', 'text', array('label' => Mage::helper('mdg_giftregistry')->__('Event Location'),'class'=> 'required-entry','required'  => true,'name'=> 'event_location',)); 
   $fieldset->addField('event_date', 'text', array('label'=> Mage::helper('mdg_giftregistry')->__('Event Date'),'class'=> 'required-entry', 'required'  => true,'name'=> 'event_date',));      
   $fieldset->addField('event_country', 'text', array('label'=> Mage::helper('mdg_giftregistry')->__('Event Country'),'class'=> 'required-entry','required'  => true,'name'=> 'event_country',));
   $form->setValues($data);
   return parent::_prepareForm();        
}    
}

And my config to admin part is:

app/design/adminhtml/default/default/layout/giftregistry.xml

<layout version="0.1.0"> 
    <adminhtml_customer_edit>         
        <reference name="left">             
            <reference name="customer_edit_tabs">                 
                <block type="mdg_giftregistry/adminhtml_customer_edit_tab_giftregistry" name="tab_giftregistry_main" template="mdg/giftregistry/customer/main.phtml">                     
                    <block type="mdg_giftregistry/adminhtml_customer_edit_tab_giftregistry_list" name="tab_giftregistry_list" as="giftregistry_list" />                 
                </block>                 
                <action method="addTab">                     
                    <name>mdg_giftregistry</name>                     
                    <block>mdg_giftregistry/adminhtml_customer_edit_tab_giftregistry</block>                 
                </action>             
            </reference>         
        </reference>     
    </adminhtml_customer_edit> 
    <adminhtml_giftregistry_index> 
        <reference name="content">              
            <block type="mdg_giftregistry/adminhtml_registries" name="registries" />          
        </reference>      
    </adminhtml_giftregistry_index>
    <adminhtml_giftregistry_edit>    
        <reference name="content">     
           <block type="mdg_giftregistry/adminhtml_registries_edit" name="new_registry_tabs" />       
        </reference>  
    </adminhtml_giftregistry_edit>
</layout>

I check the paths of the files and it's ok but i don't know where it's the error

Thanks for help!

Edit: I'm found other ask like this there but: a) I don't see the solution and b) in the comments talk about create in Helper/Data.php one class extends to Mage_Core_Helper_Abstract but i have this yet and the problem continues :(

Edit: All my config.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>        
    <Mdg_Giftregistry>             
        <version>0.1.0</version>         
    </Mdg_Giftregistry>     
</modules>     
<frontend>
    <layout>
        <updates>            
            <mdg_giftregistry module="mdg_giftregistry">                
                <file>mdg_giftregistry.xml</file>            
            </mdg_giftregistry>        
        </updates>    
    </layout>
       <routers>
           <mdg_giftregistry>         
               <use>standard</use>                 
               <args>                     
                   <module>Mdg_Giftregistry</module>                     
                   <frontName>giftregistry</frontName>                 
               </args>             
           </mdg_giftregistry>
       </routers>
   </frontend>
   <admin>
       <routers>    
           <adminhtml>      
               <args>        
                   <modules>          
                       <mdg_giftregistry before="Mage_Adminhtml">Mdg_Giftregistry_Adminhtml</mdg_giftregistry>        
                   </modules>      
               </args>    
           </adminhtml>  
       </routers> 
   </admin>
   <adminhtml>         
       <layout>             
           <updates>                 
               <mdg_giftregistry module="mdg_giftregistry">         
                <file>giftregistry.xml</file>                 
               </mdg_giftregistry>             
            </updates>
         </layout>
   </adminhtml>
<global>
    <models>             
        <mdg_giftregistry>                 
            <class>Mdg_Giftregistry_Model</class> 
            <resourceModel>mdg_giftregistry_mysql4</resourceModel>                        
        </mdg_giftregistry>         
        <mdg_giftregistry_mysql4>
            <class>Mdg_Giftregistry_Model_Mysql4</class>     
            <entities>             
                <entity>                 
                    <table>mdg_giftregistry_entity</table>             
                </entity>             
                <item>                 
                    <table>mdg_giftregistry_item</table>             
                </item>             
                <type>                 
                    <table>mdg_giftregistry_type</table>             
                </type>         
            </entities>
        </mdg_giftregistry_mysql4>
    </models>         
    <blocks>             
        <mdg_giftregistry>                 
            <class>Mdg_Giftregistry_Block</class>             
        </mdg_giftregistry>         
    </blocks>         
    <helpers>             
        <mdg_giftregistry>                 
            <class>Mdg_Giftregistry_Helper</class>             
        </mdg_giftregistry>         
    </helpers>         
    <resources>             
        <mdg_giftregistry_setup>                 
              <setup>                     
                <module>Mdg_Giftregistry</module>
                <class>Mdg_Giftregistry_Model_Resource_Setup</class>
              </setup>         
              <connection>
                  <use>core_setup</use>
              </connection>
        </mdg_giftregistry_setup>      
        <mdg_giftregistry_write>
            <connection>
                <use>core_write</use>
            </connection>            
        </mdg_giftregistry_write>
        <mdg_giftregistry_read>
            <connection>
                <use>core_read</use>
            </connection>
        </mdg_giftregistry_read>
   </resources>   
</global>   
</config>

Edit: I saw the anwer from Marius and my Edit.php it's the next: File: app/code/local/Mdg/Giftregistry/Block/Adminhtml/Registries/Edit.php

class Mdg_Giftregistry_Block_Adminhtml_Registries_Edit extends Mage_Adminhtml_Block_Widget_Form_Container{
   public function __construct(){                      
       parent::__construct();
        $this->_objectId = 'id';   
        $this->_blockGroup = 'registries';
        $this->_controller = 'adminhtml_registries';
        $this->_mode = 'edit'; 
        $this->_updateButton('save', 'label', Mage::helper('mdg_giftregistry')->__('Save'));  
        $this->_updateButton('delete', 'label', Mage::helper('mdg_giftregistry')->__('Delete'));                 
    }     

    public function getHeaderText(){         
        if(Mage::registry('registries_data') && Mage::registry('registries_data')->getId()){             
            return Mage::helper('mdg_giftregistry')->__("Edit Registry '%s'", $this->htmlEscape(Mage::registry('registries_data')->getTitle()));        
        }else{
            return Mage::helper('mdg_giftregistry')->__('Add Registry');     
        }
    }

    protected function _prepareLayout(){
    if ($this->_blockGroup && $this->_controller && $this->_mode) {
        $this->setChild('form', $this->getLayout()->createBlock($this->_blockGroup . '/' . $this->_controller . '_' . $this->_mode . '_form'));
    }
    return parent::_prepareLayout();
}


}

In the book, the values of $_controller and $_blockGroup it's the same... :(

  • Please add the config.xml of your module in the question. – Marius May 22 '14 at 10:52
  • Edit the question...sorry i'm forgot put the config.xml – Marcos May 22 '14 at 11:16
  • See any strange in the code? – Marcos May 22 '14 at 15:39
  • Hey...anybody found the error? I saw my tutorial and the steps are the same... :( :( – Marcos Jun 4 '14 at 6:32
  • Most probably the error is in the Edit.php class of your module. Check the values for $_blockGroup and $_controller variables – Marius Jun 5 '14 at 12:28
1

According to the given code snippets, Magento tries to instantiate a block of the type

$this->_blockGroup . '/' . $this->_controller . '_' . $this->_mode . '_form'

which resolves to

registries/adminhtml_registries_edit_form

There is no block of that type in your codes. There is a block of the type

mdg_giftregistry/adminhtml_registries_edit_form

but it cannot be resolved (autoloaded) as the corresponding class is not defined in an appropriate file path. It should be located at app/code/local/Mdg/Giftregistry/Block/Adminhtml/Registries/Edit/Form.php instead of app/code/local/Mdg/Giftregistry/Block/Registries/Edit/Form.php.

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.