gpt4 book ai didi

php - 如何在 CMS 中创建必填字段

转载 作者:行者123 更新时间:2023-12-04 17:51:27 25 4
gpt4 key购买 nike

我尝试在 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: the method 'getname' doesn't exist on RequiredFields or the method is not public".

如何在 SilverStripe CMS 中创建必填字段?

最佳答案

在 CMS 中,我们可以通过声明 getCMSValidator 函数并返回 RequiredFields 来声明必填字段:

public function getCMSValidator()
{
return RequiredFields::create(
'DocType',
'DocTitle',
'DocNumber'
);
}

关于php - 如何在 CMS 中创建必填字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45673510/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com