0

我刚刚按照http://symfony.com/doc/current/cookbook/form/dynamic_form_modification.html来信,以使我的文件上传字段仅显示在“新”表单上,而不是“编辑”表单上.

 $form->add($this->factory->createNamed('file', 'file', array('required' => true)));

我在“新”表单上收到此错误,但“编辑”表单很好。这对有经验的人来说可能很明显,但这是我的第一个 SF 项目,我不确定为什么食谱教程会导致我出错。

The form's view data is expected to be an instance of class Symfony\Component\HttpFoundation\File\File, but is a(n) array. You can avoid this error by setting the "data_class" option to null or by adding a view transformer that transforms a(n) array to an instance of Symfony\Component\HttpFoundation\File\File.

有人可以澄清这个问题吗?提前致谢

4

1 回答 1

0

改变

$form->add($this->factory->createNamed('file', 'file', array('required' => true)));

$form->add($this->factory->createNamed('file', 'file'));

修复。

于 2013-02-19T21:11:55.603 回答