更新时间:2023-12-05 17:46:34
为了能够正确删除与上传文件相关的所有媒体,必须使用适当的提供程序:
To be able to correctly delete all media related to the uploaded file, one has to use the appropiate provider:
来自奏鸣曲媒体文档
提供者类负责处理与媒体资产相关的常见事情:
A provider class is responsible for handling common things related to a media asset:
所以代码看起来像:
$media = $mediaManager->findOneBy(array('id' => $id));
//assuming you have access through $this->get to the service container
$provider = $this->get($media->getProviderName());
$provider->removeThumbnails($media);
$mediaManager->delete($media)