2013-03-13 67 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可能已经扩展了一些控制器。 由于错误指向某些控制器。