为什么我无法使用 VichUploader 删除我的图像实体?

Pie*_*aud 0 php symfony vichuploaderbundle

我使用 Symfony 4 和 Doctrine,并且使用 VichUploader 来管理我的图像。

我创建一个实体图像,当我使用这个实体添加新图像时,它就像一个魅力,但当我想用我的控制器删除它时:

    public function delete(Image $image):Response
    {
        $em = $this->getDoctrine()->getEntityManager();
        $em->remove($image);
        $em->flush();

        return new RedirectResponse($this->generateUrl('image-index'));
    }
Run Code Online (Sandbox Code Playgroud)

我收到最奇怪的错误:

Expected argument of type "string", "NULL" given at property path "fileName".
Run Code Online (Sandbox Code Playgroud)

在我的图像实体中,`文件名是这样的:

Expected argument of type "string", "NULL" given at property path "fileName".
Run Code Online (Sandbox Code Playgroud)

处理编辑实体时会出现相同的行为。你看到我做错了什么吗?

Mas*_*one 5

看起来您在设置器上使用了类型提示,例如

pubilc function setFileName(string $name): void
{
    $this->fileName = $name;
}
Run Code Online (Sandbox Code Playgroud)

您需要使用不太严格的类型,如下所示:

pubilc function setFileName(?string $name): void
{
    $this->fileName = $name;
}
Run Code Online (Sandbox Code Playgroud)