我刚刚跟着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.
有人可以澄清一下这个问题吗?提前致谢
答案 0 :(得分:0)
更改
$form->add($this->factory->createNamed('file', 'file', array('required' => true)));
到
$form->add($this->factory->createNamed('file', 'file'));
修好了。