我有一个基本的关系编辑器GridField
,我需要GridField
使用与GridField
的上下文相关的数据来动态定义/设置通过该对象添加的任何对象的值。
class Draw extends DataObject {
private static $has_many = array(
'Items' => 'Item'
);
}
当一个项目是通过添加Draw
的Items
GridField
,我需要在定义中使用的值Item::getCMSFields()
这里有一些很好的建议:https : //www.silverstripe.org/community/forums/data-model-questions/show/21517?start=7
您可以直接使用GridField
的GridFieldDetailForm
组件,并相应地设置字段。
对我有用的代码是:
$config = GridFieldConfig_RecordEditor::create();
if($this->exists()) {
// Ensure that fields are generated with knowledge of the parent
$editComponent = $config->getComponentByType('GridFieldDetailForm');
$item = new Item();
$item->DrawID = $this->ID;
$editComponent->setFields($item->getCMSFields());
}
$items = new GridField('Items', 'Items', $this->Items(), $config);
$fields->addFieldToTab('Root.Main', $items);
然后,您可以Draw::get()->byID($this->DrawID)
从Item::getCMSFields()
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句