I am new to magento. I am trying to write module to report abuse about site.I have the form on below page.
http://localhost/magento/vendorinfo/page/report/
Module name is vendorinfo, controller is page and action is report. Below is my ReportAction which has taken from my Venderinfo module
public function reportsubmitAction() {
$data = $this->getRequest()->getParams();
try {
$insert_data = array();
$insert_data['reporter_name'] = $data['name'];
$insert_data['reporter_email'] = $data['email'];
$insert_data['report_category'] = $data['category_type'];
$insert_data['reporter_comment'] = $data['report_comments'];
$model = Mage::getModel('vendorinfo/report');
$model->setData($insert_data)->setId(null); // i have got the error on this line
$model->setCreatedTime(now())->setUpdateTime(now());
$model->save();
Mage::getSingleton('frontend/session')->addSuccess(Mage::helper('articles')->__('Report was successfully submitted'));
Mage::getSingleton('frontend/session')->setFormData(false);
} catch (Exception $e) {
Mage::getSingleton('frontend/session')->addError($e->getMessage());
Mage::getSingleton('frontend/session')->setFormData($data);
$this->_redirect('vendorinfo/page/report', array());
return;
}
}
When i submit the form i called the above action to store my data to DB. But i ‘ve got this below error,
Fatal error: Call to a member function getIdFieldName() on a
non-object in
C:\xampp\htdocs\magento\app\code\core\Mage\Core\Model\Abstract.php on
line 151
Also i have create the 2 model files under the following folder structure,
1. Venderinfo/Model/Report.php
class Comp_Vendorinfo_Model_Report extends Mage_Core_Model_Abstract
{
public function _construct()
{
parent::_construct();
$this->_init('vendorinfo/report_abuse');
}
}
2.Venderinfo/Model/Mysql4/Report/Collection.php
class Comp_Vendorinfo_Model_Mysql4_Report_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
{
public function _construct()
{
parent::_construct();
$this->_init('vendorinfo/report_abuse');
}
}
What i done wrong on this?
Kindly advice on this.
You need to create a resource model
Venderinfo/Model/Mysql4/Report.phpand declare it in your config. In your database table, you should have an ID field such asreport_id, and this name must be defined in the constructor of the resource model.http://www.magentocommerce.com/knowledge-base/entry/magento-for-dev-part-5-magento-models-and-orm-basics