【问题标题】:Silverstripe 3 - Image relation on SiteConfig DataObjectSilverstripe 3 - SiteConfig DataObject 上的图像关系
【发布时间】:2013-06-19 02:04:03
【问题描述】:

SS 不保存 DataObject(扩展名)与 Image 的关系;我认为问题可能出在 SiteConfig ModelAdmin 上。

这是(部分)站点配置扩展类:

class CustomSiteConfig extends DataExtension { 
    static $has_many = array(
        'HeaderSections' => 'HeaderSection',
        'FooterSections' => 'FooterSection',
    );

    public function updateCMSFields(FieldList $fields) {
        ...
        $fields->addFieldToTab('Root.Header', $gridFieldHeader);
        ...
    }
}

当然,我已经在 _config 中添加了所需的代码。

这是(部分)DataObject 扩展 HeaderSection:

class HeaderSection extends DataObject {
    public static $has_many = array(
        'Sections' => 'HeaderSubSection'
    );

    public function getCMSFields() {
        ...
        $gridField = new GridField('Sections', 'Dropdown Sections', $this->Sections(), $gridFieldConfig);
        ...
    }
}

而属于HeaderSection的DataObject扩展类称为HeaderSubSection:

class HeaderSubSection extends DataObject {
    static $has_one = array(
        'HeaderSection' => 'HeaderSection',
        'InternalLink' => 'SiteTree',
        'Image' => 'Image'
    );

    public function getCMSFields() {
        ...
        $fields->addFieldToTab('Root.Main', new UploadField('Image', 'Section Image', $this->Image()));
        ...
    }
}

一切正常,所有其他字段都保存(包括“内部链接”及其关系),但是我无法保存图像。

我是否需要将标题部分移动到它自己的 ModelAdmin 页面,然后以某种方式将它们链接回 SiteConfig?

【问题讨论】:

  • 不应该HeaderSection 与 SiteConfig 有 $has_one 关系吗?虽然,不确定它是否相关。
  • @colymba 这会破坏 SS。

标签: silverstripe


【解决方案1】:

我最终向 has_one 添加了另一个 Image 字段,并且成功了。

猜测 SS 不喜欢将图像字段命名为“图像”。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-04-17
    • 1970-01-01
    • 1970-01-01
    • 2020-04-02
    • 2018-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多