2016-12-28 60 views
0

我需要在表格中保存表格數據。我需要知道更好的方法。從控制器存儲更好嗎?我已經使用下面的代碼,但沒有成功嘗試如何通過控制器在表格中存儲表格數據

形式

<form id="orderapproval-item-form" class="orderapproval-hidden" action="<?php echo $this->getUrl('orderapproval/customercart/remarksdecline');?>" method="post"> 
<input type="text" name="message" class="orderapproval-disabled" value="<?php echo $this->__('Enter decline reason'); ?>" id="decline" /> 
<input type="submit" value="<?php echo $this->__('Decline'); ?>" onclick="namet()" /> 

控制器

public function remarksdeclineAction() 
    { 
     $model =Mage::getModel('OrderApproval/sales_quote_item_order'); 
$model->setItemcomment($message); 
$model->save(); // save data 

    } 

模型/ orderapproval.php

<?php 
class ZetaPrints_OrderApproval_Model_OrderApproval extends Mage_Core_Model_Abstract 
{ 
     public function _construct() 
    { 
     $this->_init('orderapproval/sales_quote_item_order'); 
    } 
} 

模型/資源/ orderapproval.php

<?php 
class ZetaPrints_OrderApproval_Model_Resource_OrderApproval extends Mage_Core_Model_Resource_Db_Abstract 
{ 
     public function _construct() 
    { 
     $this->_init('orderapproval/sales_quote_item_order', 'item_id'); 
    } 
} 

模型/資源/ orderapproval/collection.php

<?php 
class ZetaPrints_OrderApproval_Model_Resource_OrderApproval_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract 
{ 
     protected function _constuct(){ 
$this->_init('orderapproval/sales_quote_item_order'); 
} 
} 

config.xml中

<?xml version="1.0" ?> 
<config> 
    <modules> 
    <ZetaPrints_OrderApproval> 
     <version>3</version> 
    </ZetaPrints_OrderApproval> 
    </modules> 

    <global> 
    <models> 
     <orderapproval> 
     <class>ZetaPrints_OrderApproval_Model</class> 
     <resourceModel>ZetaPrints_OrderApproval_resource</resourceModel> 
     </orderapproval> 

     <ZetaPrints_OrderApproval_resource> 
     <class>ZetaPrints_OrderApproval_Model_Resource</class> 
     <entities> 
      <OrderApproval> 
       <table>sales_quote_item_order</table> 
      </OrderApproval> 
      </entities> 
    </ZetaPrints_OrderApproval_resource> 

     <sales> 
     <rewrite> 
      <quote>ZetaPrints_OrderApproval_Model_Quote</quote> 
     </rewrite> 
     </sales> 
    </models> 

    <blocks> 
     <orderapproval> 
     <class>ZetaPrints_OrderApproval_Block</class> 
     </orderapproval> 
    </blocks> 

    <helpers> 
     <orderapproval> 
     <class>ZetaPrints_OrderApproval_Helper</class> 
     </orderapproval> 
    </helpers> 

    <resources> 
     <orderapproval_setup> 
     <setup> 
      <module>ZetaPrints_OrderApproval</module> 
      <class>Mage_Eav_Model_Entity_Setup</class> 
     </setup> 
     <connection> 
      <use>Core_setup</use> 
     </connection> 
     </orderapproval_setup> 

     <orderapproval_write> 
     <connection><use>Core_write</use></connection> 
     </orderapproval_write> 

     <orderapproval_read> 
     <connection><use>Core_read</use></connection> 
     </orderapproval_read> 
    </resources> 

其我的文件夾名稱和型號的文件夾的文件名

ZetaPrints/OrderApproval/Model/orderapproval.php 



ZetaPrints/OrderApproval/Model/Resource/orderapproval.php 
ZetaPrints/OrderApproval/Model/Resource/orderapproval/connection.php 
+0

我收到錯誤.....致命錯誤:未捕獲的錯誤:布爾 –

+0

*我需要調用一個成員函數setItemcomment()知道更好的方式*和現在*我得到錯誤* ..兩個不同的陳述。 – mmushtaq

+0

抱歉,我沒有得到您的控制器正在呼叫的 –

回答

0

使用以下代碼在控制器中。

$variable = $this->getRequest()->getParam('form_element'); 

最終代碼與此類似。

public function remarksdeclineAction() 
{ 
$variable = $this->getRequest()->getParam('form_element'); 
$model = Mage::getModel('orderapproval/orderapproval'); 
$model->setItemcomment($variable); 
$model->save(); // save data 
} 

也請仔細config.xml中再次檢查命名空間

+0

我的模塊名稱是zetaprints_orderapproval –

+0

我應該寫在這裏命名空間或模塊名稱 –

+0

我是獲取此錯誤致命錯誤:未捕獲錯誤:調用成員函數beginTransaction()布爾 –

相關問題