【发布时间】: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