我和symfony5在一起。我选择了easyAdminBundle。为了上传图片,我尝试使用vichUploaderBundle。问题是它只能工作一次。例如,对于服务实体,它只在我创建一个新服务(例如: seo、网站或打印)时才能工作。当我更改已经存在的服务的映像时,它将不再工作。我跟着官方网站上的教程 ..。
# config/services.yaml
parameters:
app.path.website_images: /images
# config/packages/vich_uploader.yaml
vich_uploader:
db_driver: orm
mappings:
website_images:
uri_prefix: '%app.path.website_images%'
upload_destination: '%kernel.project_dir%/public%app.path.website_images%'
?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\ServiceRepository")
* @Vich\Uploadable
*/
class Service
{
[...]
/**
* @ORM\Column(type="string", length=255)
*/
private $image;
/**
* @Vich\UploadableField(mapping="website_images", fileNameProperty="image")
*/
private $imageFile;
/**
* @ORM\Column(type="datetime")
*/
private $updatedAt;
[...]
}
# config/packages/easy_admin.yaml
Service:
label: 'Service'
class: App\Entity\Service
list:
fields:
- { property: 'title' }
- { property: 'image', type: 'image', base_path: '%app.path.website_images%' }
form:
fields:
- { property: 'title' }
- { property: 'imageFile', type: 'vich_image' }
- { property: 'content', type: 'fos_ckeditor' }有时候很管用,但大多数时候都不行.
发布于 2020-01-08 11:36:10
public function setImage(string $image): self
=>
public function setImage(?string $image): self位置错误在设置器级别。必须添加问号才能接受null。
https://stackoverflow.com/questions/59603205
复制相似问题