我正在尝试创建一个自定义 magento 扩展。
它有效,只有 1 个表单字段未保存到数据库中。
public function saveAction()
{
if ($postData = $this->getRequest()->getPost()) {
$model = Mage::getSingleton('foo_bar/baz');
$model->setData($postData);
try {
$model->save();
Mage::getSingleton('adminhtml/session')->addSuccess($this->__('The baz has been saved.'));
$this->_redirect('*/*/');
return;
}
catch (Mage_Core_Exception $e) {
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
}
catch (Exception $e) {
Mage::getSingleton('adminhtml/session')->addError($this->__('An error occurred while saving this baz.'));
}
Mage::getSingleton('adminhtml/session')->setBazData($postData);
$this->_redirectReferer();
}
}
表格:
protected function _prepareForm()
{
$model = Mage::registry('foo_bar');
$form = new Varien_Data_Form(array(
'id' => 'edit_form',
'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
'method' => 'post'
));
$fieldset = $form->addFieldset('base_fieldset', array(
'legend' => Mage::helper('checkout')->__('Baz Information'),
'class' => 'fieldset-wide',
));
if ($model->getId()) {
$fieldset->addField('id', 'hidden', array(
'name' => 'id',
));
}
$fieldset->addField('name', 'text', array(
'name' => 'name',
'label' => Mage::helper('checkout')->__('Name'),
'title' => Mage::helper('checkout')->__('Name'),
'required' => true,
));
$fieldset->addField('stock', 'text', array(
'name' => 'stock',
'label' => Mage::helper('checkout')->__('stock'),
'title' => Mage::helper('checkout')->__('stock'),
'required' => true,
));
$form->setValues($model->getData());
$form->setUseContainer(true);
$this->setForm($form);
return parent::_prepareForm();
}
}
“库存字段未保存”的值。
我检查了数据库中存在列库存,并且名称相同。
有谁知道我做错了什么?
提前致谢。