我尝试在CMS中创建所需的字段:
class Documents extends DataObject {
private static $db = array(
'DocType' => 'Text',
'DocTitle' => 'Text',
'DocNumber' => 'Text'
);
public function getCMSFields() {
$fields = parent::getCMSFields();
$fields = FieldList::create(TabSet::create('Root'));
$fields->addFieldsToTab('Root.Main', array(
DropdownField::create('DocType','Document Type'),
DropdownField::create('DocStatus','Document Status'),
TextField::create('DocNumber','Document Number'),
...
RequiredFields::create(array('DocType','DocTitle','DocNumber'));
));
return $fields;
}
但在我的SilverStripe错误日志中,我得到以下内容:
“Uncaught Exeption:RequiredFields上不存在方法'getname',或者该方法不公开”。
如何在SilverStripe CMS中创建所需的字段?
答案 0 :(得分:6)
在CMS中,我们可以通过声明getCMSValidator
函数并返回RequiredFields
来声明必填字段:
public function getCMSValidator()
{
return RequiredFields::create(
'DocType',
'DocTitle',
'DocNumber'
);
}