2013-03-13 64 views
0

大家好我是新的magento,我試圖在管理部分的數據庫中插入記錄。這是控制器文件的功能。Magento - 想要在管理部分中插入magento中的記錄

public function saveAction() 
    { 
     $data = $this->getRequest()->getParams(); 
     $arrData = array('number_of_products'=>$data['number_of_products'],'price'=>$data['price']); 
     $model = Mage::getModel('a/totebags')->setData($arrData); 
     try { 
      $insertId = $model->save()->getId(); 
      echo "Data successfully inserted. Insert ID: ".$insertId; 
     } catch (Exception $e){ 
      echo $e->getMessage(); 
     } 
    } 

我的問題是,當運行此代碼,然後我得到這個錯誤:

Fatal error: Call to a member function setData() on a non-object in /Library/WebServer/Documents/magento/app/code/community/ToteBags/Adminform/controllers/Adminhtml/AdminformController.php on line 40 

這是我​​3210

<?xml version="1.0"?> 
<config> 
    <modules> 
     <ToteBags_Adminform> 
      <version>1.0.0</version> 
     </ToteBags_Adminform> 
    </modules> 

    <global> 
     <blocks> 
      <totebags_adminform> 
       <class>ToteBags_Adminform_Block</class> 
      </totebags_adminform> 
     </blocks> 

     <helpers> 
      <totebags_adminform> 
       <class>ToteBags_Adminform_Helper</class> 
      </totebags_adminform> 
     </helpers> 

     <models> 
      <totebags_adminform> 
       <class>ToteBags_Adminform_Model</class> 
       <resourceModel>totebags_adminform_mysql4</resourceModel> 
      </totebags_adminform> 
      <totebags_adminform_mysql4> 
       <class>ToteBags_Adminform_Model_Mysql4</class> 
       <entities> 
        <category> 
         <table>totebags_fbstore_category</table> 
        </category> 
        <category_product> 
         <table>totebags_fbstore_category_product</table> 
        </category_product> 
       </entities> 
      </totebags_adminform_mysql4> 
     </models> 

     <resources> 
      <totebags_adminform_setup> 
       <setup> 
        <module>ToteBags_Adminform</module> 
       </setup> 
       <connection> 
        <use>core_setup</use> 
       </connection> 
      </totebags_adminform_setup> 
      <totebags_adminform_write> 
       <connection> 
        <use>core_write</use> 
       </connection> 
      </totebags_adminform_write> 
      <totebags_adminform_read> 
       <connection> 
        <use>core_read</use> 
       </connection> 
      </totebags_adminform_read> 
     </resources> 
    </global> 

    <admin> 
     <routers> 
      <adminhtml> 
       <args> 
        <modules> 
         <totebags_adminform after="Mage_Adminhtml">ToteBags_Adminform_Adminhtml</totebags_adminform> 
        </modules> 
       </args> 
      </adminhtml> 
     </routers> 
    </admin> 

    <adminhtml> 
     <layout> 
      <updates> 
       <totebags_adminform> 
        <file>totebags_adminform.xml</file> 
       </totebags_adminform> 
      </updates> 
     </layout> 
     <translate> 
      <modules> 
       <ToteBags_Adminform> 
        <files> 
         <default>ToteBags_Adminform.csv</default> 
        </files> 
       </ToteBags_Adminform> 
      </modules> 
     </translate> 
    </adminhtml> 

    <default> 
     <totebags_adminform> 
      <general> 
       <default_sort_by><![CDATA[position]]></default_sort_by> 
      </general> 
     </totebags_adminform> 
    </default> 
</config> 

請幫助我。

+0

你有沒有試過看看'Mage :: getModel('a/totebags')'是否返回一個對象? – justderb 2013-03-13 15:03:32

+0

這裏有一個類似的線程有問題的人:http://www.magentocommerce.com/boards/viewthread/71277/ – justderb 2013-03-13 15:06:39

+0

感謝@justerb這個鏈接,我現在就讀它。 – Kabir 2013-03-13 15:11:07

回答

0

你有沒有上傳應用程序的/ etc /模塊/ modulename.xml有codePool由namespace_modulename細節是這樣的

真正 核心

替換Mage_Connect文件

看起來像上面你已經完成的部分。

控制器未使用類Varien_Object進行擴展,因此沒有setData與Controller類實例一起使用。 $ model = Mage :: getModel('a/totebags') - > setData($ arrData);

什麼類擴展到創建你的Model.You可能已經擴展了一些控制器。 由於錯誤指向某些控制器。