I have a problem with my custom module.. in the form i get that error : Fatal error: Call to a member function setData()
on boolean in /wwwroot/whitelabel/01/app/code/core/Mage/Adminhtml/Block/Widget/Form/Container.php
on line 141
My config.xml
<?xml version="1.0" encoding="utf-8" ?>
<config>
<modules>
<Integravet_Associar>
<version>0.1.0</version>
</Integravet_Associar>
</modules>
<admin>
<routers>
<adminhtml>
<args>
<modules>
<associar before="Mage_Adminhtml">Integravet_Associar_Adminhtml</associar>
</modules>
</args>
</adminhtml>
</routers>
</admin>
<adminhtml>
<layout>
<updates>
<associar>
<file>integravet_associar.xml</file>
</associar>
</updates>
</layout>
</adminhtml>
<global>
<helpers>
<integravet_associar>
<class>Integravet_Associar_Helper</class>
</integravet_associar>
</helpers>
<blocks>
<integravet_associar>
<class>Integravet_Associar_Block</class>
</integravet_associar>
</blocks>
<models>
<integravet_associar>
<class>Integravet_Associar_Model</class>
<resourceModel>integravet_associar_resource</resourceModel>
</integravet_associar>
<integravet_associar_resource>
<class>Integravet_Associar_Model_Resource</class>
<entities>
<associar>
<table>integravet_associar</table>
</associar>
</entities>
</integravet_associar_resource>
</models>
<resources>
<integravet_associar_write>
<connection>
<use>core_write</use>
</connection>
</integravet_associar_write>
<integravet_associar_read>
<connection>
<use>core_read</use>
</connection>
</integravet_associar_read>
<integravet_associar_setup>
<setup>
<module>Integravet_Associar</module>
<class>Mage_Catalog_Model_Resource_Eav_Mysql4_Setup</class>
</setup>
<connection>
<use>core_setup</use>
</connection>
</integravet_associar_setup>
</resources>
</global>
</config>
My adminhtml.xml
<config>
<menu>
<integravet translate="title" module="integravet_ramo">
<title>Integravet</title>
<sort_order>100</sort_order>
<children>
<associar translate="title" module="integravet_associar">
<title>Associar Ramo de Atividade</title>
<sort_order>1</sort_order>
<action>adminhtml/associar/index</action>
</associar>
</children>
</integravet>
</menu>
<acl>
<resources>
<admin>
<children>
<integravet translate="title">
<title>Integravet</title>
<sort_order>100</sort_order>
<children>
<associar translate="title" module="integravet_associar">
<title>Associar Ramo de Atividade</title>
<sort_order>0</sort_order>
</associar>
</children>
</integravet>
</children>
</admin>
</resources>
</acl>
</config>
My controller
<?php
/**
* Created by PhpStorm.
* User: williansugiyama
* Date: 22/08/17
* Time: 15:49
*/
class Integravet_Associar_Adminhtml_AssociarController extends Mage_Adminhtml_Controller_Action {
protected function _initAction() {
$this->loadLayout()->_setActiveMenu('integravet_associar/set_time')->_addBreadcrumb('Ramos de atividade', 'Ramos de atividade');
return $this;
}
public function indexAction(){
$this->_initAction();
$this->renderLayout();
}
public function editAction(){
$ramoId = $this->getRequest()->getParam('id');
$ramoModel = Mage::getModel('integravet_associar/associar')->load($ramoId);
if($ramoModel->getId() || $ramoId == 0) {
Mage::register('associar_data', $ramoModel);
$this->loadLayout();
$this->_setActiveMenu('integravet_associar/set_time');
$this->_addBreadcrumb('Ramos de atividade', 'Ramos de atividade');
$this->_addBreadcrumb('Descrição do ramo', 'Descrição do ramo');
$this->getLayout()->getBlock('head')
->setCanLoadExtJs(true);
$this->_addContent($this->getLayout()
->createBlock('integravet_associar/adminhtml_associar_edit'))
->_addLeft($this->getLayout()
->createBlock('integravet_associar/adminhtml_associar_edit_tabs')
);
$this->renderLayout();
} else {
Mage::getSingleton('adminhtml/session')->addError('Ramo não existe.');
$this->_redirect('*/*/');
}
}
public function newAction() {
$this->_forward('edit');
}
public function saveAction(){
if($this->getRequest()->getParam('id') <= 0) {
if($this->getRequest()->isPost()) {
try {
$postData = $this->getRequest()->getPost();
if($this->getRequest()->getParam('id') <= 0) {
$ramoModel = Mage::getModel('integravet_associar/associar')->load($this->getRequest()->getParam('id'));
} else {
$ramoModel = Mage::getModel('integravet_associar/associar');
}
$ramoModel->setCreatedTime( Mage::getSingleton('core/date')->gmtDate() );
$ramoModel->addData($postData)
->setId()
->setcreated_at(Mage::getSingleton('core/date')->gmtDate())
->save();
$this->_redirect('*/*/');
return;
} catch (Exception $e) {
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
Mage::getSingleton('adminhtml/session')->setramoData($this->getRequest()->getPost());
$this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
return;
}
}
} else {
try {
$postData = $this->getRequest()->getPost();
$ramoModel = Mage::getModel('integravet_associar/associar')->load($this->getRequest()->getParam('id'));
$ramoModel->addData($postData)->setupdated_at(Mage::getSingleton('core/date')->gmtDate())
->setId($this->getRequest()->getparam('id'))
->save();
$this->_redirect('*/*/');
} catch ( Exception $e ) {
echo $e->getMessage();
$this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
return;
}
}
}
public function deleteAction() {
if($this->getRequest()->getParam('id') > 0) {
try {
$ramoModel = Mage::getModel('integravet_associar/associar');
$ramoModel->setId($this->getRequest()->getParam('id')->delte());
Mage::getSingleton('adminhtml/session')->addSuccess('Ramo Deletado com sucesso');
} catch (Exception $e) {
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
$this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
}
}
$this->_redirect('*/*/');
}
}
My Grid.php
<?php
/**
* Created by PhpStorm.
* User: williansugiyama
* Date: 22/08/17
* Time: 14:29
*/
class Integravet_Associar_Block_Adminhtml_Grid extends Mage_Adminhtml_Block_Widget_Grid_Container {
public function __construct()
{
$this->_controller = 'adminhtml_associar';
$this->_blockGroup = 'integravet_associar';
$this->_headerText = 'Associar ramos de atividade';
$this->_addButtonLabel = 'Associar';
parent::__construct();
}
}
My Edit.php
class Integravet_Associar_Block_Adminhtml_Associar_Edit extends Mage_Adminhtml_Block_Widget_Form_Container {
public function __construct()
{
parent::__construct();
$this->_objectId = 'id';
$this->_blockGroup = 'adminhtml_associar';
$this->_controller = 'integravet_associar';
$this->_updateButton('save', 'label', 'Salvar associação');
$this->_updateButton('delete', 'label', 'Deletar associação');
}
public function getHeaderText()
{
if (Mage::registry('associar_data') && Mage::registry('associar_data')->getId()) {
return 'Editar Associação ' . $this->htmlEscape(Mage::registry('associar_data')->getTitle());
} else {
return 'Adicionar Associação';
}
}
}
My tabs.php
<?php
/**
* Created by PhpStorm.
* User: williansugiyama
* Date: 22/08/17
* Time: 14:51
*/
class Integravet_Associar_Block_Adminhtml_Associar_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs {
public function __construct()
{
parent::__construct();
$this->setId('associar_tabs');
$this->setDestElementId('edit_form');
$this->setTitle('Informações do ramo');
}
protected function _beforeToHtml()
{
$this->addTab('form_section', array(
'label' => 'About the movie',
'title' => 'About the movie',
'content' => $this->getLayout()
->createBlock('integravet_associar/adminhtml_associar_edit_tab_form')
->toHtml()
));
return parent::_beforeToHtml();
}
}
My Form.php
<?php
/**
* Created by PhpStorm.
* User: williansugiyama
* Date: 22/08/17
* Time: 14:56
*/
class Integravet_Associar_Block_Adminhtml_Associar_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',
)
);
$form->setUseContainer(true);
$this->setForm($form);
return parent::_prepareForm();
}
}
My Tab/Form.php
<?php
/**
* Created by PhpStorm.
* User: williansugiyama
* Date: 22/08/17
* Time: 14:58
*/
class Integravet_Associar_Block_Adminhtml_Associar_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form {
protected function _prepareForm() {
$form = new Varien_Data_Form();
$this->setForm($form);
$fieldset = $form->addFieldset('edit_form', array (
'legend' => 'Informações do ramo'
));
$fieldset
->addField('name', 'text', array(
'label' => 'Ramo de Atividade',
'class' => 'required-entry',
'required' => true,
'name' => 'name',
))
->addField('id_erp', 'text', array (
'label' => 'ID ERP',
'class' => 'required-entry',
'required' => true,
'id_erp' => 'id_erp'
))
->addField('website_id','multiselect', array (
'label' => 'teste',
'class' => 'required-entry',
'required' => true,
'values' => Mage::getSingleton('core/resource_website_collection')->toOptionArray(),
));
if(Mage::registry('associar_data')) {
$form->setValues(Mage::registry('associar_data')->getData());
}
return parent::_prepareForm();
}
}
->setcreated_at(Mage::getSingleton('core/date')->gmtDate())
- this line in save action seems wrong. It should besetCreatedAt