![](/img/trans.png)
[英]How can I solve “Type error: Argument 2 passed to … must be an instance of Symfony\Component\HttpFoundation\File\UploadedFile”?
[英]Catchable Fatal Error: Argument 1 passed to \Entity\Image::setFile() must be an instance of Symfony\Component\HttpFoundation\File\UploadedFile,
我有这个错误
可捕获的致命错误:传递给swaam \\ ImageUploaderBundle \\ Entity \\ Image :: setFile()的参数1必须是Symfony \\ Component \\ HttpFoundation \\ File \\ UploadedFile的实例,
给定的swaam \\ ImageUploaderBundle \\ Entity \\ Image实例,在438行上在D:\\ xamp \\ htdocs \\ shams \\ vendor \\ symfony \\ symfony \\ src \\ Symfony \\ Component \\ PropertyAccess \\ PropertyAccessor.php中调用,并在D:\\ xamp \\中定义htdocs \\ shams \\ src \\ swaam \\ ImageUploaderBundle \\ Entity \\ Image.php第166行
根据提到的行号166其功能setFile()这是我的功能
public function setFile(UploadedFile $file = null)
{
$this->file = $file;
// check if we have an old image path
if (isset($this->path)) {
// store the old name to delete after the update
$this->temp = $this->path;
$this->path = null;
} else {
$this->path = 'initial';
}
}
我什至无法理解错误,任何人都可以帮助我,并解释一下错误的原因以及可能的解决方案。
我也收到类似的错误消息。 我通过在表单标签中添加<form method="post" {{ form_enctype(form) }}>
来解决此问题。
当在用于表示实体的字段的表单中使用choice
字段类型时,出现此错误。
为了解决这个问题,我将choice
更改为buildForm
entity
,并添加了该实体应解析为选项的类,因此add
语句开始如下所示:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add(
'product',
'entity',
[
'class' => 'Acme\AppBundle\Entity\Product',
]
);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.