Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Simple form leads to “Call to a member function setData() on a non-object”
 
frinux
Jr. Member
 
Total Posts:  6
Joined:  2009-09-01
 

Hi,
I’m trying to build a simple form. In my controller, I have this action :

public function editAction()
    
{
        $this
->loadLayout();
        
$this->_setActiveMenu('catalog');
        
$layout $this->getLayout()->createBlock('manufacturingorder/adminhtml_edit');
        
$this->_addContent($layout);
        
$this->renderLayout();
    
}

I have a form container :

<?php
class Smile_ManufacturingOrder_Block_Adminhtml_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
    
{
    
public function __construct() {         
        parent
::__construct();
        
        
$this->_blockGroup 'manufacturingorder';
        
$this->_mode 'edit';
        
$this->_controller 'adminhtml_view';
        
    
}
    
public function getHeaderText() {
        
return Mage::helper('manufacturingorder')->__('Détail du lot');
    
}
}

and a form :

<?php
class Smile_ManufacturingOrder_Block_Adminhtml_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
{
    
public function __construct() {

        parent
::__construct();
        
$this->setId('edit_form');
        
    
}

    
    
protected function _prepareForm()
    
{
        
//$commands = Mage::registry('commandsIds'); // récup en session
        
        
$dateFormatIso Mage::app()->getLocale()->getDateFormat(
            
Mage_Core_Model_Locale::FORMAT_TYPE_SHORT
        
);
        
        
$form = new Varien_Data_Form(array(
            
'id' => 'package_form',
            
'action' => $this->getUrl('*/*/prepare', array()),
            
'method' => 'post'
        
));
        
        
$fieldset   $form->addFieldset('base_fieldset', array(
            
'legend'    => Mage::helper('manufacturingorder')->__('Lot'),
        ));
        
        
$fieldset->addField('lot''text', array(
            
'name'      => 'lot',
            
'label'     => Mage::helper('manufacturingorder')->__('Numéro de lot'),
            
'required'  => true,
        ));
        
        
$fieldset->addField('date''date', array(
            
'name'      => 'date',
            
'label'     => Mage::helper('manufacturingorder')->__('Date/heure de lancement'),
            
'image'     => $this->getSkinUrl('images/grid-cal.gif'),
            
'format'    => $dateFormatIso,
            
'required'  => true,
        ));
        
        
/*
        $fieldset->addField('id', 'hidden', array(
            'name'      => 'id',
            'value'     => $commands,
        ));
        */
        
        
        
$form->setUseContainer(true);
        
$this->setForm($form);
        
        return 
parent::_prepareForm();
    
}
}

Now, when I go to this action, I get a message :

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

Allthough the save and cancel buttons are displayed, there is this exception instead of the form.

Any hint please?

 
Magento Community Magento Community
Magento Community
Magento Community
 
rsingh
Jr. Member
 
Total Posts:  11
Joined:  2008-10-06
 

I am also getting same error while creating a form in admin module

 
Magento Community Magento Community
Magento Community
Magento Community
 
rsingh
Jr. Member
 
Total Posts:  11
Joined:  2008-10-06
 

This is fixed for me, I compare my code to http://www.magentocommerce.com/wiki/custom_module_with_custom_database_table and found that controller path ($this->_controller) was wrong, I missed adminhtml_with it and controller was in adminhtml directory.

So compare your product with http://www.magentocommerce.com/wiki/custom_module_with_custom_database_table, it may help you.

 
Magento Community Magento Community
Magento Community
Magento Community
 
frinux
Jr. Member
 
Total Posts:  6
Joined:  2009-09-01
 

It’s not the case, my controller is OK. Thanks, though

 
Magento Community Magento Community
Magento Community
Magento Community
 
Travis Apple
Jr. Member
 
Total Posts:  9
Joined:  2010-02-10
 

Make sure you have your blockgroup set correctly

$this->_blockGroup = ‘<module>’;
in
<Namespace>_<Module>_Block_Adminhtml_<Module>_Edit

This should match with your config.xml :

<blocks>
<module>
<class><Namespace>_<Module>_Block</class>
</module>
</blocks>

 
Magento Community Magento Community
Magento Community
Magento Community
 
Script Kiddi3
Jr. Member
 
Total Posts:  18
Joined:  2010-05-24
Rawalpindi
 

I am creating a magento extention…

Call to a member function setData() on a non-object

I dont know from where this bug just came out.

Can any one help....

Regards,
Tauseef

 
Magento Community Magento Community
Magento Community
Magento Community
 
cstef
Jr. Member
 
Avatar
Total Posts:  10
Joined:  2008-06-17
 

I have this same error, but not with a custom widget.  I get this error when trying to \"manage stores\” when I click on a store, this error prevents the form from displaying.  We ugraded to Magento 1.4.0.1 when it came out and have never needed to manage the stores until now.  Any information would be very helpful, thanks!

 
Magento Community Magento Community
Magento Community
Magento Community
 
Anthony Charrex
Member
 
Avatar
Total Posts:  47
Joined:  2008-08-25
Geneva, Switzerland
 

The variable “$_controller” allows to specifiy group of blocks participating in the edition action.

Here the correct code based on the configuration described above :

<?php
class Smile_ManufacturingOrder_Block_Adminhtml_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
    
{
    
public function __construct() {         
        parent
::__construct();
        
        
$this->_blockGroup 'manufacturingorder';
        
$this->_mode 'edit'// defined by default
        
$this->_controller 'adminhtml';
        
    
}
    
public function getHeaderText() {
        
return Mage::helper('manufacturingorder')->__('Détail du lot');
    
}
}

If your class name was “Smile_ManufacturingOrder_Block_Adminhtml_Toto_Edit”, the variable “$this->_controller” should be defined to “adminhtml_toto”.

 
Magento Community Magento Community
Magento Community
Magento Community
 
fabs
Jr. Member
 
Total Posts:  10
Joined:  2011-03-11
 
Travis Apple - 15 February 2010 01:32 AM

Make sure you have your blockgroup set correctly

$this->_blockGroup = ‘<module>’;
in
<Namespace>_<Module>_Block_Adminhtml_<Module>_Edit

Thank you very much! I had the same problem and had hard time debugging it the last few days, this one finally helped me out

 
Magento Community Magento Community
Magento Community
Magento Community
 
Bright Ideas
Sr. Member
 
Total Posts:  140
Joined:  2011-04-17
Mumbai
 
fabs - 20 April 2011 04:39 AM

Travis Apple - 15 February 2010 01:32 AM
Make sure you have your blockgroup set correctly

$this->_blockGroup = ‘<module>’;
in
<Namespace>_<Module>_Block_Adminhtml_<Module>_Edit

Thank you very much! I had the same problem and had hard time debugging it the last few days, this one finally helped me out

Hello,
Can you tell me where should I write this code. I am getting the same error.

I would be very much thankful to you.

Regards
Dushyant Joshi

 
Magento Community Magento Community
Magento Community
Magento Community
 
Bright Ideas
Sr. Member
 
Total Posts:  140
Joined:  2011-04-17
Mumbai
 

thanks Ash Singh smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
vlozanov
Jr. Member
 
Total Posts:  1
Joined:  2012-04-05
 
Travis Apple - 15 February 2010 01:32 AM

Make sure you have your blockgroup set correctly

$this->_blockGroup = ‘<module>’;
in
<Namespace>_<Module>_Block_Adminhtml_<Module>_Edit

This should match with your config.xml :

<blocks>
<module>
<class><Namespace>_<Module>_Block</class>
</module>
</blocks>

This solved my problem too.

Thanks Travis you made my day.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top