【发布时间】:2019-12-14 23:50:28
【问题描述】:
我正在尝试向我的 Silverstripe CMS 添加一个简单的 GridField,其中仅包含 HTMLEditorFields。我正在使用GridFieldConfig_RecordEditor。当我单击“添加部分”时,出现内部服务器错误。然后如果我刷新页面,我会收到以下错误:
Uncaught BadMethodCallException: Object->__call(): the method 'dataFieldByName' does not exist on 'SilverStripe\Forms\HTMLEditor\HTMLEditorField'
我不知道是什么原因造成的。有人知道为什么会这样吗?
这是我Page.php中的代码:
<?php
namespace {
use SilverStripe\CMS\Model\SiteTree;
use Silverstripe\Forms\CheckboxField;
use Silverstripe\Forms\FieldGroup;
use Silverstripe\Forms\HTMLEditor\HTMLEditorField;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
use SilverStripe\ORM\DataObject;
class Section extends DataObject {
private static $db = [
'SectionContent' => 'HTMLText'
];
private static $has_one = [
'Page' => Page::class
];
public function getCMSFields() {
return HTMLEditorField::create('SectionContent');
}
}
class Page extends SiteTree {
private static $db = [
'IncludeSections' => 'Boolean'
];
private static $has_many = [
'Sections' => Section::class
];
public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab(
'Root.Main',
FieldGroup::create(
CheckboxField::create("IncludeSections")
), 'Content'
);
if ($this->IncludeSections) {
$fields->addFieldToTab('Root.Main',
$grid = GridField::create(
'Sections',
'Sections in this page. Seperated by boxes.',
$this->Sections(),
GridFieldConfig_RecordEditor::create()
)
);
}
return $fields;
}
}
}
【问题讨论】:
标签: silverstripe-4