gpt4 book ai didi

php - Symfony 4 easy admin 和 vich uploader 捆绑错误

转载 作者:行者123 更新时间:2023-12-02 07:49:44 26 4
gpt4 key购买 nike

我正在使用 vich-uploader bundle 与 easy-admin 和 symfony4。设置后,我在尝试删除或更新实体时收到此错误

Expected argument of type "string", "NULL" given at property path "imageName".

对于这种常见情况,应用程序的配置是最简单的。矿井测试实体:

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;


/**
* @ORM\Entity(repositoryClass="App\Repository\TestRepository")
* @Vich\Uploadable
*/
class Test
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;

/**
* @ORM\Column(type="string", length=255)
*/
private $imageName;

/**
* @Vich\UploadableField(mapping="test_images", fileNameProperty="imageName")
* @var File
*/
private $imageFile;

/**
* @ORM\Column(type="datetime")
* @var \DateTime
*/
private $updatedAt;


public function getId()
{
return $this->id;
}

public function getImageName()
{
return $this->imageName;
}

public function setImageName(string $image)
{
$this->imageName = $image;

return $this;
}

public function setImageFile(File $image = null)
{
$this->imageFile = $image;

if ($image) {
$this->updatedAt = new \DateTime('now');
}
}

public function getImageFile()
{
return $this->imageFile;
}


public function getUpdatedAt()
{
return $this->updatedAt;
}

public function setUpdatedAt(\DateTime $datetime)
{
$this->updatedAt = $datetime;

return $this;
}
}

我的简单管理yaml配置

easy_admin:
entities:
Test:
class: App\Entity\Test
form:
fields:
- { property: 'imageFile', type: 'vich_image' }
# ...
list:
fields:
- { property: 'image', type: 'image', base_path: '%app.path.banner_images%' }
# ...
show:
fields:
- { property: 'image', type: 'image', base_path: '%app.path.banner_images%' }

最佳答案

尝试使用

public function setImageName(?string $image)
{
$this->imageName = $image;

return $this;
}

关于php - Symfony 4 easy admin 和 vich uploader 捆绑错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53836372/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com