我需要在表格中保存表单数据。我需要知道更好的方法。从控制器存储更好吗?我尝试使用以下代码但没有成功
形式
<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)
在控制器中使用以下代码。
$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中再次检查命名空间