简体   繁体   English

可捕获的致命错误:传递给\\ Entity \\ Image :: setFile()的参数1必须是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,

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.

相关问题 如何解决“类型错误:传递给...的参数2必须是Symfony \ Component \ HttpFoundation \ File \ UploadedFile”的实例? - How can I solve “Type error: Argument 2 passed to … must be an instance of Symfony\Component\HttpFoundation\File\UploadedFile”? Symfony 2嵌入式表单:可捕获的致命错误:传递给Entity的参数1 :: addProperty必须是XX \\ MyClass的一个实例,给出的数组 - Symfony 2 Embedded Forms: Catchable Fatal Error: Argument 1 passed to Entity::addProperty must be an instance of XX\MyClass, array given Symfony2可捕获的致命错误:参数1传递给实体可捕获的致命错误:参数1传递给实体 - Symfony2 Catchable Fatal Error: Argument 1 passed to entity Catchable Fatal Error: Argument 1 passed to entity 可捕获的致命错误:传递给Symfony :: render()的参数3必须是Symfony \\ .. \\ Response的实例,给定数组 - Catchable Fatal Error: Argument 3 passed to Symfony::render() must be an instance of Symfony\..\Response, array given Symfony 2可捕获的致命错误:传递给Sg \\ DatatablesBundle \\ Datatable \\ :: __ construct()的参数1必须是的实例 - Symfony 2 Catchable Fatal Error: Argument 1 passed to Sg\DatatablesBundle\Datatable\::__construct() must be an instance of 主义(Symfony3)可捕获的致命错误:传递给(bundle)的参数1必须是(bundle)的实例,给定数组 - Doctrine (Symfony3) Catchable Fatal Error: Argument 1 passed to (bundle) must be an instance of (bundle), array given Laravel 6中的多文件上传器:“必须是Symfony \\ Component \\ HttpFoundation \\ File \\ UploadedFile的实例,已指定数组” - Multiple file uploader in Laravel 6: “must be an instance of Symfony\Component\HttpFoundation\File\UploadedFile, array given” 可捕获的致命错误:传递给...的参数1必须是...,给定数组的实例 - Catchable Fatal Error: Argument 1 passed to … must be an instance of …, array given 在Symfony2中上载文件:可捕获的致命错误:参数1传递给 - Upload file in Symfony2: Catchable Fatal Error: Argument 1 passed to 不允许序列化 &#39;Symfony\\Component\\HttpFoundation\\File\\UploadedFile&#39; - Serialization of 'Symfony\Component\HttpFoundation\File\UploadedFile' is not allowed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM