![](/img/trans.png)
[英]Fatal error: Call to a member function getIdFieldName() on a non-object in Magento
[英]How to fix this getIdFieldName fatal error in magento?
我是magento的新手。 我正在尝试编写模块来报告有关网站的滥用行为。我在下面的页面上有表格。
http://localhost/magento/vendorinfo/page/report/
模块名称为vendorinfo,控制器为页面,操作为报告。 下面是我ReportAction
这是从我Venderinfo模块采取
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;
}
}
当我提交表单时,我调用了上述操作将数据存储到DB。 但我有以下错误,
致命错误:在第151行的C:\\ xampp \\ htdocs \\ magento \\ app \\ code \\ core \\ Mage \\ Core \\ Model \\ Abstract.php中的非对象上调用成员函数getIdFieldName()
我还在以下文件夹结构下创建了2个模型文件,
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 /型号/ Mysql4 /报告/ 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');
}
}
我做错了什么?
请就此提出建议。
您需要创建一个资源模型Venderinfo/Model/Mysql4/Report.php
并在您的配置中声明它。 在数据库表中,您应该有一个ID字段,例如report_id
,并且必须在资源模型的构造函数中定义此名称。
请转到magento root file-> app / etc并检查local.xml文件,如果这里不可用,请将local.xml复制到另一个magento目录并在此处编辑和复制。
问题已解决
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.