在SilverStripe 3.1中,我有一个扩展DataObject
的类has_one Image
。
当用户从CMS上传图像时,如何为要上传的图像文件指定特定文件夹?
答案 0 :(得分:2)
在我的类getCMSFields函数中,我得到了Image的UploadField,然后调用了setFolderName函数:
class BannerImage extends DataObject {
private static $has_one = array(
'Page' => 'Page',
'Image' => 'Image'
);
public function getCMSFields() {
$fields = parent::getCMSFields();
/** @var UploadField $uploadField */
$uploadField = $fields->fieldByName('Root.Main.Image');
$uploadField->setFolderName("banners");
...