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

时间:2012-03-01 05:54:04

标签: php 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。但我有以下错误,

  

致命错误:在a上调用成员函数getIdFieldName()   非对象   C:\ xampp \ htdocs \ magento \ app \ code \ core \ Mage \ Core \ Model \ Abstract.php on   第151行

我还在以下文件夹结构下创建了2个模型文件,

1。 Venderinfo /型号/ 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');
        }
    }

我在这方面做错了什么?

请就此提出建议。

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:0)

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

问题已解决