我必须从XML Feed导入以下结构:
例如:
我创建了两个DataObjects,如下所示:
ExpertiseTag.ss
class ExpertiseTag extends DataObject {
private static $db = [
'SortID' => 'Int',
'Title' => 'Varchar'
];
private static $has_one = [
'MemberPage' => 'MemberPage'
];
private static $has_many = [
'ExpertiseSubTags' => 'ExpertiseSubTag'
];
public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->removeByName('SortID');
$fields->removeByName('MemberPageID');
$fields->addFieldToTab('Root.Main', TextField::create( 'Title', 'Tag naam' ) );
return $fields;
}
}
ExpertiseSubTag.ss
class ExpertiseSubTag extends DataObject {
private static $db = [
'SortID' => 'Int',
'Title' => 'Varchar'
];
private static $has_one = [
'ExpertiseTag' => 'ExpertiseTag'
];
public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->removeByName('SortID');
$fields->addFieldToTab('Root.Main', TextField::create( 'Title', 'Tag naam' ) );
return $fields;
}
}
也许ListboxField不是可行的方法,但理想情况下我想创建一种情况,我可以看到嵌套结构并进行多项选择。要继续:在持有人页面上,我创建了一个ListboxField,我想列出其中一个dataobjects的dataobjects。
ListboxField看起来像这样:
$fields->addFieldToTab('Root.Expertise', ListboxField::create(
'ExpertiseTags',
'Expertise (tags):',
ExpertiseTag::get()->map('ID', 'Title')->toArray(),
$this->ExpertiseTags()->column('ID'),
null,
true
));
如何调整或重新创建代码以实现上述情况?也许ListboxField不是这里的方式。