[英]Catchable Fatal Error: Argument 1 passed to \Entity\Image::setFile() must be an instance of Symfony\Component\HttpFoundation\File\UploadedFile,
I Got this error 我有这个错误
Catchable Fatal Error: Argument 1 passed to swaam\\ImageUploaderBundle\\Entity\\Image::setFile() must be an instance of Symfony\\Component\\HttpFoundation\\File\\UploadedFile, 可捕获的致命错误:传递给swaam \\ ImageUploaderBundle \\ Entity \\ Image :: setFile()的参数1必须是Symfony \\ Component \\ HttpFoundation \\ File \\ UploadedFile的实例,
instance of swaam\\ImageUploaderBundle\\Entity\\Image given, called in D:\\xamp\\htdocs\\shams\\vendor\\symfony\\symfony\\src\\Symfony\\Component\\PropertyAccess\\PropertyAccessor.php on line 438 and defined in D:\\xamp\\htdocs\\shams\\src\\swaam\\ImageUploaderBundle\\Entity\\Image.php line 166 给定的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行
according to the mention line no 166 its the function setFile() here is my function 根据提到的行号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';
}
}
I couldn't even understand the error , any one please help me and explain a bit the reason of the error plus the possible solution. 我什至无法理解错误,任何人都可以帮助我,并解释一下错误的原因以及可能的解决方案。
I've got a similar error message. 我也收到类似的错误消息。 I solved it by adding
<form method="post" {{ form_enctype(form) }}>
to my form tag. 我通过在表单标签中添加
<form method="post" {{ form_enctype(form) }}>
来解决此问题。
I got this error when using choice
field type in a form for a field that represented an entity. 当在用于表示实体的字段的表单中使用
choice
字段类型时,出现此错误。
To fix this I changed choice
to entity
in buildForm
and also added class that this entity is supposed to resolve to to options, so add
statement started to look as following: 为了解决这个问题,我将
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.