简体   繁体   English

致命错误:在Magento中的非对象上调用成员函数getIdFieldName()

[英]Fatal error: Call to a member function getIdFieldName() on a non-object in Magento

I have created a custom module in both frontend and backend called vendor complaints, I am getting the form, but when i fill the details and click on save I am getting the fatal error. 我已经在前端和后端都创建了一个名为供应商投诉的自定义模块,我正在获取表单,但是当我填写详细信息并单击“保存”时,我将收到致命错误。

My Config.xml file: 我的Config.xml文件:

     <?xml version="1.0"?>
        <config>
          <modules>
            <Blazedream_VendorComplaints>
              <version>0.1.0</version>
            </Blazedream_VendorComplaints>
          </modules>
          <frontend>
            <routers>
              <vendorcomplaints>
                <use>standard</use>
                  <args>
                    <module>Blazedream_VendorComplaints</module>
                    <frontName>vendorcomplaints</frontName>
                  </args>
              </vendorcomplaints>
            </routers>
            <layout>
                  <updates>
                    <vendorcomplaints>
                      <file>vendorcomplaints.xml</file>
                    </vendorcomplaints>
                  </updates>
            </layout>
          </frontend>
          <global>
            <helpers>
              <vendorcomplaints>
                <class>Blazedream_VendorComplaints_Helper</class>
              </vendorcomplaints>
            </helpers>
            <blocks>
              <vendorcomplaints>
                <class>Blazedream_VendorComplaints_Block</class>
              </vendorcomplaints>
            </blocks>
            <models>
              <vendorcomplaints>
                <class>Blazedream_VendorComplaints_Model</class>
                <resourceModel>VendorComplaints_mysql4</resourceModel>
              </vendorcomplaints>
              <vendorcomplaints_mysql4>
                <class>Blazedream_VendorComplaints_Model_Mysql4</class>
                <entities>        
                      <complaints>
                        <table>vendor_complaints</table>
                      </complaints>
                </entities>
              </vendorcomplaints_mysql4>
            </models>
            <resources>
              <vendorcomplaints_setup>
                <setup>
                  <module>Blazedream_VendorComplaints</module>
                </setup>
                <connection>
                  <use>core_setup</use>
                </connection>
              </vendorcomplaints_setup>
              <vendorcomplaints_write>
                <connection>
                  <use>core_write</use>
                </connection>
              </vendorcomplaints_write>
              <vendorcomplaints_read>
                <connection>
                  <use>core_read</use>
                </connection>
              </vendorcomplaints_read>
            </resources>
          </global>
           <admin>
            <routers>
              <vendorcomplaints>
                <use>admin</use>
                <args>
                  <module>Blazedream_VendorComplaints</module>
                  <frontName>vendorcomplaints</frontName>
                </args>
              </vendorcomplaints>
            </routers>
          </admin>
           <adminhtml>
            <menu>
            <marketplace>
                <children>
                    <complaints module="vendorcomplaints">
                    <title>Manage Complaints</title>
                    <sort_order>0</sort_order>
                    <action>admin_vendorcomplaints/adminhtml_complaints</action>
                  </complaints>
                </children>
            </marketplace>
            </menu>
            <acl>
                <resources>
                    <all>
                    <title>Allow Everything</title>
                    </all>
                    <admin>
                        <children>
                            <vendorcomplaints>
                                <title>Complaints Module</title>
                                <sort_order>200</sort_order>
                            </vendorcomplaints>
                        </children>
                    </admin>
                </resources>
            </acl>
            <layout>
              <updates>
                <vendorcomplaints>
                  <file>vendorcomplaints.xml</file>
                </vendorcomplaints>
              </updates>
            </layout>
          </adminhtml>
        </config> 

My Controller file: local/Blazedream/VendorComplaints/controllers/indexcontroller.php 我的控制器文件:local / Blazedream / VendorComplaints / controllers / indexcontroller.php

        <?php
    class Blazedream_VendorComplaints_IndexController extends Mage_Core_Controller_Front_Action{

        public function IndexAction() {
          $this->checkurlForVendor();
          $this->loadLayout();   
          $this->getLayout()->getBlock("head")->setTitle($this->__("Seller Complaints"));
                $breadcrumbs = $this->getLayout()->getBlock("breadcrumbs");
          $breadcrumbs->addCrumb("home", array(
                    "label" => $this->__("Home Page"),
                    "title" => $this->__("Home Page"),
                    "link"  => Mage::getBaseUrl()
               ));

          $breadcrumbs->addCrumb("Seller Complaints", array(
                    "label" => $this->__("Seller Complaints"),
                    "title" => $this->__("Seller Complaints")
               ));

          $this->renderLayout(); 

        }
        public function saveAction()
        {
            $post_data=$this->getRequest()->getPost();
            $roleId = Mage::getSingleton('customer/session')->getCustomerGroupId();
            $role = Mage::getSingleton('customer/group')->load($roleId)->getData('customer_group_code');
            $role = strtolower($role);
            $post_data['customer_group']=$role;
            $customerName=$post_data['name'];
            $customerEmail=$post_data['email_id'];
            if ($post_data) {
                try {
                    $model = Mage::getModel("vendorcomplaints/complaints")
                        ->addData($post_data)
                        ->setId($this->getRequest()->getParam("id"))
                        ->save();
                    Mage::getSingleton('core/session')->addSuccess('Vendor Complaints was successfully saved');
                    $this->_redirect("*/*/");
                    return;
                } 
                catch (Exception $e) {
                    Mage::getSingleton("adminhtml/session")->addError($e->getMessage());
                    Mage::getSingleton("adminhtml/session")->setComplaintsData($this->getRequest()->getPost());
                    $this->_redirect("*/*/edit", array("id" => $this->getRequest()->getParam("id")));
                    return;
                }
            }
            $this->_redirect("*/*/");
        }
        protected function _getSession()
            {
                return Mage::getSingleton('customer/session');
            }
            protected function checkVendorIsActive()
        {
            return Mage::helper('marketplace')->getVendorStatus();
        }

        function checkvendorisLogged(){
             $session = $this->_getSession();
             if (!$session->isLoggedIn()) {
                Mage::getSingleton('customer/session')->addError(Mage::helper('marketplace')->__("Please Login to your account"));
                $this->_redirect('sellerlogin');
             }
        }
            public function checkurlForVendor()
            {
            $session = $this->_getSession();

            if (!$session->isLoggedIn()) {
                Mage::getSingleton('customer/session')->addError(Mage::helper('marketplace')->__("Please login as seller"));
                $this->_redirect('sellerlogin');
            } else {
                $isEnable        = Mage::getStoreConfig('marketplace/general/enable');
                $isModuleEnabled = Mage::helper('core')->isModuleOutputEnabled('NextBits_Marketplace');
                $isActive        = $this->checkVendorIsActive();
                $action_name = trim($this->getRequest()->getActionName());

                if ($isModuleEnabled && $isEnable){


                    if ($isActive == 0 || $isActive == "") {
                        Mage::getSingleton('customer/session')->addError(Mage::helper('marketplace')->__("Seller not activated yet, or you are not a seller."));
                        $this->_redirect('marketplace/vendor/dashboard/');
                    }

                } else {

                    Mage::getSingleton('customer/session')->addError(Mage::helper('marketplace')->__("Marketplace Module is disable."));
                    $this->_redirect('marketplace/vendor/dashboard/');
                }
            }
        }
    }

My Block File: local/Blazedream/VendorComplaints/Block/index.php 我的阻止文件:local / Blazedream / VendorComplaints / Block / index.php

    <?php   
        class Blazedream_VendorComplaints_Block_Index extends Mage_Core_Block_Template{   

            public function __construct(){

                    parent::__construct();
                    $this->setTemplate('vendorcomplaints/index.phtml');
            }
            protected function _prepareLayout()
            {
                $this->setChild('save_button',
                        $this->getLayout()->createBlock('adminhtml/widget_button')
                            ->setData(array(
                                'label'     => Mage::helper('vendorcomplaints')->__('Submit'),
                                'onclick'   => 'vendorComplaints.submit()',
                                'class' => 'save'
                            ))
                    );
                parent::_prepareLayout();
            }
            public function getBackButtonHtml()
            {
                return $this->getChildHtml('back_button');
            }

            public function getCancelButtonHtml()
            {
                return $this->getChildHtml('reset_button');
            }

            public function getSaveButtonHtml()
            {
                return $this->getChildHtml('save_button');
            }

            public function getSaveAndEditButtonHtml()
            {
                return $this->getChildHtml('save_and_edit_button');
            }

            public function getDeleteButtonHtml()
            {
                return $this->getChildHtml('delete_button');
            }

            public function getDuplicateButtonHtml()
            {
                return $this->getChildHtml('duplicate_button');
            }
             public function getValidationUrl()
            {
                return $this->getUrl('*/*/validate', array('_current'=>true));
            }

            public function getSaveUrl()
            {
                return $this->getUrl('*/*/save', array('_current'=>true, 'back'=>null));
            }
        }

My form block file for creating the form: ocal/Blazedream/VendorComplaints/Block/Complaints/Edit/Form.php 我用于创建表单的表单块文件:ocal / Blazedream / VendorComplaints / Block / Complaints / Edit / Form.php

       <?php
     class Blazedream_VendorComplaints_Block_Complaints_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
    {
    protected function _prepareForm()
    {
            $customer = Mage::getSingleton('customer/session')->getCustomer();
            $customerId=$customer->getId();
            $data = Mage::getModel('marketplace/vendor')
                ->getCollection()
                ->addFieldToFilter('customer_id',$customerId)
                ->getData();

            $cus_name=$customer->getName();
            $emailId=$customer->getEmail();
            $form = new Varien_Data_Form();
            $this->setForm($form);
            $fieldset = $form->addFieldset("vendorcomplaints_form", array("legend"=>Mage::helper("vendorcomplaints")->__("Item information")));

            $three_columns = "col-xs-12 col-sm-4 col-md-4 col-lg-4";
            $one_column = "col-xs-12 col-sm-12 col-md-12 col-lg-12";

                    $fieldset->addField("vendor_complaints_id", "hidden", array(
                    "label" => Mage::helper("vendorcomplaints")->__("Id"),
                    "name" => "vendor_complaints_id",
                    ));

                    $fieldset->addField("name", "text", array(
                    "label" => Mage::helper("vendorcomplaints")->__("First Name"),
                    "name" => "name",
                    "class"=> "required-entry",
                    'readonly'=>true,
                    'required' => true,
                    'value' =>$cus_name,
                    'container_class' => $three_columns
                    ));

                    $fieldset->addField("order_id", "text", array(
                    "label" => Mage::helper("vendorcomplaints")->__("Order Id"),
                    "name" => "order_id",
                    'required' => true,
                    "class"=> "required-entry",
                    'container_class' => $three_columns
                    ));

                    $fieldset->addField("email_id", "text", array(
                    "label" => Mage::helper("vendorcomplaints")->__("Email Id"),
                    "name" => "email_id",
                    'value'=>$emailId,
                    'required' => true,
                    'readonly'=>true,
                    "class"=> "required-entry validate-email",
                    'container_class' => $three_columns
                    ));

                    $fieldset->addField("reason", "textarea", array(
                    "label" => Mage::helper("vendorcomplaints")->__("Reason"),
                    "name" => "reason",
                    'required' => true,
                    "class"=> "required-entry",
                    'container_class' => $one_column
                    ));             

            if (Mage::getSingleton("adminhtml/session")->getComplaintsData())
            {
                $form->setValues(Mage::getSingleton("adminhtml/session")->getComplaintsData());
                Mage::getSingleton("adminhtml/session")->setComplaintsData(null);
            } 
            elseif(Mage::registry("complaints_data")) {
                $form->setValues(Mage::registry("complaints_data")->getData());
            }
            return parent::_prepareForm();
             }
            }

My model file : local/Blazedream/VendorComplaints/Model/Complaints.php 我的模型文件:local / Blazedream / VendorComplaints / Model / Complaints.php

        <?php

    class Blazedream_VendorComplaints_Model_Complaints extends Mage_Core_Model_Abstract
  {
protected function _construct(){

   $this->_init("vendorcomplaints/complaints");

   }

  }

local/Blazedream/VendorComplaints/Model/Mysql4/Complaints.php 本地/Blazedream/VendorComplaints/Model/Mysql4/Complaints.php

        <?php
     class Blazedream_VendorComplaints_Model_Mysql4_Complaints extends Mage_Core_Model_Mysql4_Abstract
   {
      protected function _construct()
    {
    $this->_init("vendorcomplaints/complaints", "vendor_complaints_id");
    }
     } 

local/Blazedream/VendorComplaints/Model/Mysql4/Complaints/Collection.php 本地/Blazedream/VendorComplaints/Model/Mysql4/Complaints/Collection.php

      <?php
   class Blazedream_VendorComplaints_Model_Mysql4_Complaints_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
{

    public function _construct(){
        $this->_init("vendorcomplaints/complaints");
    }



}

My sql Setup file:local/Blazedream/VendorComplaints/sql/vendorcomplaints_setup 我的SQL安装文件:本地/ Blazedream / VendorComplaints / sql / vendorcomplaints_setup

       <?php
    $installer = $this;
    $installer->startSetup();
    $sql=<<<SQLTEXT
    create table vendor_complaints(vendor_complaints_id int not null auto_increment,name varchar(1000) not null,order_id varchar(100) NOT NULL,email_id varchar(100) not null,reason text,customer_group varchar(100) not null, primary key(vendor_complaints_id));
        insert into vendor_complaints values(1,'tablename1','3','www@gmail.com','asxasxsx','sadasd');


    SQLTEXT;

    $installer->run($sql);

    $installer->endSetup();

After that i have loaded xml file and view file.. I got the complaint form, but when i enter the details and click on save button I am getting the fatal error.. I dont know where i had done the mistakes.. 之后,我已经加载了xml文件和查看文件..我收到了投诉表,但是当我输入详细信息并单击“保存”按钮时,我得到了致命错误..我不知道我在哪里犯了错误..

Can anyone help me to find the issue???? 谁能帮我找到问题????

Change these line in IndexController.php 在IndexController.php中更改这些行

$model = Mage::getModel("vendorcomplaints/complaints")
                    ->addData($post_data)
                    ->setId($this->getRequest()->getParam("id"))
                    ->save();

To

$id = $this->getRequest()->getParam("id");
$model = Mage::getModel("vendorcomplaints/complaints")->load($id)->addData($post_data);
$model->setId($id)->save();

Because you need to load the table row id before updating the data. 因为您需要在更新数据之前加载表的行ID。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Magento:致命错误:在非对象上调用成员函数 getMethodInstance() - Magento : Fatal error: Call to a member function getMethodInstance() on a non-object Magento致命错误-在非对象上调用成员函数getId() - Magento Fatal Error - Call to a member function getId() on a non-object Magento致命错误:在非对象上调用成员函数save() - Magento Fatal error: Call to a member function save() on a non-object 致命错误:在 magento 中的非对象上调用成员函数 getLevel() - Fatal error: Call to a member function getLevel() on a non-object in magento Magento:致命错误:在非对象上调用成员函数 load() - Magento: Fatal error: Call to a member function load() on a non-object 致命错误:在magento中的非对象上调用成员函数getEmail() - Fatal error: Call to a member function getEmail() on a non-object in magento Magento致命错误:在非对象上调用成员函数addFieldToFilter() - Magento Fatal error: Call to a member function addFieldToFilter() on a non-object Magento致命错误:在非对象上调用成员函数getSku() - Magento Fatal Error: Call to member function getSku() on a non-object Magento:致命错误:在非对象上调用成员函数getItems() - Magento: Fatal error: Call to a member function getItems() on a non-object Magento遇到此错误:致命错误:在非对象上调用成员函数getAttributeText() - Magento getting this error: Fatal error: Call to a member function getAttributeText() on a non-object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM