我正在创建自定义管理模块,其中网格,编辑,新建,删除工作与产品网格相同。一切正常,但当我点击网格行编辑项目时,它正确重定向,但文本字段不包含数据。目前我有一个名为name editAction的字段如下:
public function editAction()
{
$id = $this->getRequest()->getParam('id', null);
$model = Mage::getModel('fondation/fondation');
if ($id) {
$model->load((int) $id);
if ($model->getId()) {
$data = Mage::getSingleton('adminhtml/session')->getFormData(true);
if ($data) {
$model->setData($data)->setId($id);
}
} else {
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('fondation')->__('Example does not exist')); $this->_redirect('*/*/');
}
}
Mage::register('fondation_data', $model);
$this->loadLayout();
$this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
$this->renderLayout();
}
表格
class Npm_Fondation_Block_Adminhtml_Fondation_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form
{
protected function _prepareForm()
{
$form = new Varien_Data_Form();
$this->setForm($form);
$fieldset = $form->addFieldset('fondation_form', array('legend'=>Mage::helper('fondation')->__('Item information')));
$fieldset->addField('Name', 'text', array(
'label' => Mage::helper('fondation')->__('Name'),
'class' => 'required-entry',
'required' => true,
'name' => 'name',
));
if (Mage::getSingleton('adminhtml/session')->getFondationData()) {
$form->setValues(Mage::getSingleton('adminhtml/session')->getFondationData());
Mage::getSingleton('adminhtml/session')->setFondationData(null);
} elseif (Mage::registry('fondation_data')) {
$form->setValues(Mage::registry('fondation_data')->getData());
}
return parent::_prepareForm();
}
}