设置要在SilverStripe中进入的图像的默认上载文件夹

时间:2015-03-26 04:15:31

标签: silverstripe

在SilverStripe 3.1中,我有一个扩展DataObject的类has_one Image

当用户从CMS上传图像时,如何为要上传的图像文件指定特定文件夹?

1 个答案:

答案 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");
    ...