如何在Silverstripe模型管理员中自动发布上传到数据对象的文件 [英] How to automaticaly publish files uploaded to a dataobject in Silverstripe model admin

查看:73
本文介绍了如何在Silverstripe模型管理员中自动发布上传到数据对象的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Silverstripe 4中,必须先发布已上传的文件,然后该文件才能在网站的公共端可见.

In Silverstripe 4 a file that is uploaded must be published before it is visible to the public side of the site.

如果我创建带有$ has_one Image :: Class的$ Page,然后将该图像分配给$ owns [],则在发布页面时将发布上载的图像.

If I create a $Page with a $has_one Image::Class and then also assign that image to $owns[] the uploaded image will be published when I publish the page.

但是,如果我创建以下数据对象结构,则不会.

However If I create the following data object structure it will not.

Class Item extends DataObject{
    $has_one[
        'ItemImage'=>Image::Class,
        'Catalog'=>'Catalog'
    ];

    $owns[
        'ItemImage'
    ]
}

Class Catalog extend DataObject{
    $has_many[
        'Items'=>'Item'
    ]
    $owns[
        'Items'
    ]

    public function getCMSFields(){
        $fields = parent::getCMSFields();

        $fields->addFieldToTab('Root.Items', GridField::create('Items', 'Items', $this->Items(), GridFieldConfig_RecordEditor::create()));

        return $fields;

    }
}

如果我创建一个目录,并在其中创建带有图像的项目,然后将其保存,它将不会发布上载的图像.我将必须手动执行以下操作: 1.选择图像 2.编辑原件 3.发布

If I create a catalog and within it create items with images and then save it, it will not publish the images that were uploaded. I will have to manually: 1. Select the image 2. Edit Original 3. Publish

必须为用户提供一种更简便的方法.

推荐答案

当前在GitHub上的多个存储库中对此进行了讨论.

This is currently discussed on GitHub on multiple repositories.

目前的解决方案是在onAfterWrite中手动发布图像,或者最好通过YML版本化您的DataObject:

The solution at the moment, is either publish the images manually in onAfterWrite, or version your DataObject, preferably via YML:

My\Data\Object
  extensions:
    - Versioned

这篇关于如何在Silverstripe模型管理员中自动发布上传到数据对象的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆