Silverstripe Dropzone:文件附件字段保存文件但不附加它

Silverstripe Dropzone: File Attachment Field saving file but not attaching it

我正在开发前端表单 让用户能够上传文件。我几乎设法让 FileAttachmentField 正常工作。它将文件上传到所需的文件夹,但我无法将上传的文件附加到它。关系是 $has_one.

    $fields->push(FileAttachmentField::create('BusinessLicense', 'Business License')
        ->setAcceptedFiles(['.pdf','.doc','.docx'])
        ->setFolderName($MemberID)
        ->setValue(null, $this)

上面的代码没有附加文件。如果我将其更改为 UploadField,如下所示:

    $fields->push(UploadField::create('IdentityCard', 'Identity Card, Passport, Driving license')
        ->setFolderName($MemberID)
        ->setValue(null, $this)
    );

有效。据我了解文档,我必须用 FileAttachmentField 替换 UploadField。谁能给我一个提示。我努力让这个工作。我看不出我做错了什么或缺少什么。

保存到 $has_one 关系时,您通常需要 ID 后缀,尽管有些字段有一些自定义魔法并且没有它也能工作。

所以像

$fields->push(FileAttachmentField::create('BusinessLicenseID', 'Business License')

应该可以