【问题标题】:Symfony2: EasyAdminbundle + StofDoctrineExtensionsBundle + VichUploaderBundleSymfony2:EasyAdminbundle + StofDoctrineExtensionsBundle + VichUploaderBundle
【发布时间】:2016-02-12 04:56:31
【问题描述】:
我有一个项目使用 EasyAdminBundle 进行管理。在一个名为“Post”的实体中,我有字段“title”、“image”和“post”,我想跟踪它们的变化。属性“image”仅存储图像的文件名 - 完整的上传过程由 VichUploaderBundle 管理。
我如何/在哪里可以网格化旧图像文件不会在更改时被删除,因为它将用于历史记录?
【问题讨论】:
标签:
symfony
stofdoctrineextensions
vichuploaderbundle
symfony2-easyadmin
gedmo-loggable
【解决方案1】:
当您定义映射时,有一种方法可以告诉 VichUploaderBundle 它不应该自动删除旧文件:
这是从捆绑包文档中获取的示例映射配置:
vich_uploader:
db_driver: orm
mappings:
product_image:
uri_prefix: /images/products
upload_destination: %kernel.root_dir%/../web/images/products
inject_on_load: false
# this prevents the file from being deleted on update
delete_on_update: false
# this prevents the file from being deleted when the
# entity itself is deleted
delete_on_remove: true