我想构建一个表单。我用下面的代码尝试了很多,但它总是给我错误。
错误:
2015-08-03T08:49:26+00:00 ERR (3): Recoverable Error: Argument 1 passed to Mage_Adminhtml_Block_Widget_Form::setForm() must be an instance of Varien_Data_Form, instance of Mage_Adminhtml_Block_System_Config_Form given, called in C:\xampp\htdocs\magentobigcom\app\code\core\Mage\Adminhtml\Block\System\Config\Form.php on line 315 and defined in C:\xampp\htdocs\magentobigcom\app\code\core\Mage\Adminhtml\Block\Widget\Form.php on line 119
2015-08-03T08:49:26+00:00 ERR (3): Recoverable Error: Argument 1 passed to Varien_Data_Form_Element_Abstract::setRenderer() must implement interface Varien_Data_Form_Element_Renderer_Interface, instance of Sample_Bigcom_Block_Adminhtml_Form_Edit_File given, called in C:\xampp\htdocs\magentobigcom\app\code\core\Mage\Adminhtml\Block\System\Config\Form.php on line 438 and defined in C:\xampp\htdocs\magentobigcom\lib\Varien\Data\Form\Element\Abstract.php on line 164
并且代码在这里:
<?php
class Sample_Bigcom_Block_Adminhtml_Form_Edit_File extends Mage_Adminhtml_Block_Widget_Form
{
protected function _prepareForm() {
$form = new Varien_Data_Form(array(
'id' => 'edit_form',
'action' => $this->getUrl('*/*/process', array('id' => $this->getRequest()->getParam('id'))),
'method' => 'post',
'enctype' => 'multipart/form-data'
)
);
return parent::_prepareForm();
}
}
有什么东西我应该在任何配置文件或系统文件中写出来摆脱这个错误吗?
有人能给我一些解决方案吗?
答案 0 :(得分:0)
您应该尝试在$ this上设置表单。
protected function _prepareForm() {
$form = new Varien_Data_Form(array(
'id' => 'edit_form',
'action' => $this->getUrl('*/*/process', array('id' => $this->getRequest()->getParam('id'))),
'method' => 'post',
'enctype' => 'multipart/form-data'
)
);
$this->setForm($form);
return parent::_prepareForm();
}
此外,我建议在表单周围使用容器(扩展Mage_Adminhtml_Block_Widget_Form_Container)。
以下是很好的教程: