今天在做项目时我想更新Magento后端中的现有表单。因为原来代码在核心文件中,所以我重写了这个类,但是当我重写完并且修改好代码之后运行发现没起作用,最后找到了一个方法解决了这个问题,在这里分享给大家:
原文件代码:
$fieldset->addField('title', 'text', array(
'label' => Mage::helper('review')->__('Summary of Review'),
'required' => true,
'name' => 'title',
));
这里我想把必填改成不必填,修改后代码如下:
class Fun_Catalog_Block_Product_Review_Edit_Form extends Mage_Adminhtml_Block_Review_Edit_Form
{
protected function _prepareForm()
{
parent::_prepareForm();
$form = $this->getForm();
$title = $form->getElement('title'); //这里的title是原文件中的'element'对应的字段
$title->setData('required', false); //这里是把自己要修改的写进去
$this->setForm($form);
return $this;
}
}