簡體   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,

我有這個錯誤

可捕獲的致命錯誤:傳遞給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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM