首页 > 解决方案 > 在 Silverstripe 4 中将 Uploadfield 设置为覆盖

问题描述

在 Silverstripe 版本 3 中,您可以设置上传文件以覆盖配置中的文件:

# replace files instead of versioning
Upload:
  replaceFile: true
# show an overwrite warning
UploadField:
  defaultConfig:
    overwriteWarning: true

我希望在 SS4 中实现相同的目标,但无法找到解决方案。根据我从文档中收集到的信息,我需要设置AssetStore::CONFLICT_OVERWRITE为 true,但我不确定在哪里执行此操作。

任何帮助将非常感激。

标签: phpfile-uploaduploadsilverstripesilverstripe-4

解决方案


AssetStore::CONFLICT_OVERWRITE是一个常数,所以你不能覆盖它。

但在UploadField::__construct()我看到:

// When creating new files, rename on conflict
$this->getUpload()->setReplaceFile(false);

所以理论上你应该能够做类似的事情:

$uploadField = UploadField::create(...);
$uploadField->getUpload()->setReplaceFile(true);

覆盖文件。


推荐阅读