如何通过控制器在表格中存储表格数据

问题描述:

我需要在表格中保存表格数据。我需要知道更好的方法。从控制器存储更好吗?我已经使用下面的代码,但没有成功尝试如何通过控制器在表格中存储表格数据

形式

<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

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

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

$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()布尔 –