首页 文章

如何修复magento中的getIdFieldName致命错误?

提问于
浏览
1

我是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/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');
        }
    }

我做错了什么?

请就此提出建议 .

2 回答

  • 3

    您需要创建资源模型 Venderinfo/Model/Mysql4/Report.php 并在配置中声明它 . 在数据库表中,您应该有一个ID字段,例如 report_id ,并且必须在资源模型的构造函数中定义此名称 .

    http://www.magentocommerce.com/knowledge-base/entry/magento-for-dev-part-5-magento-models-and-orm-basics

  • 0

    请转到magento root file-> app / etc并检查local.xml文件,如果这里不可用,请将local.xml复制到另一个magento目录并在此处编辑和复制 .

    问题得到解决

相关问题