【发布时间】:2014-12-10 17:31:53
【问题描述】:
我正在尝试使用https://github.com/silverstripe-australia/silverstripe-gridfieldextensions/ 创建一个网格字段,我可以在其中添加不同类型的数据对象。
遗憾的是,我不知道如何在我想要网格字段的班级上编写正确的代码。
有人可以指点我正确的方向吗?
更新: 根据您的回答,我现在有以下结构
class ModularPage extends Page {
private static $has_many = array(
'Sections' => 'MP_Section',
'Galleries' => 'MP_Gallery',
'Paragraphs' => 'MP_Paragraph'
);
public function getCMSFields() {
...
$fields->addFieldToTab('Root.Main', $mutli_grid = GridField::create('Sections', 'Sektionen', $this->Sections(), MultiClassGrid::create(15)));
...
}
}
class MP_Section extends DataObject {
private static $has_one = array(
'Section' => 'MP_Section',
'ModularPage' => 'ModularPage'
);
}
class MP_Gallery extends MP_Section {
private static $has_one = array(
'Section' => 'MP_Section',
'ModularPage' => 'ModularPage'
);
}
到目前为止,还好吗?直到现在都这样吗?
原因如果我想添加一个画廊,我会收到以下错误
[用户错误] 无法运行查询:SELECT DISTINCT "MP_Section"."ID", "MP_Section"."SortID" FROM "MP_Section" LEFT JOIN "MP_Gallery" ON "MP_Gallery"."ID" = "MP_Section "."ID" LEFT JOIN "MP_Paragraph" ON "MP_Paragraph"."ID" = "MP_Section"."ID" WHERE ("ModularPageID" = '13') ORDER BY "MP_Section"."SortID" ASC LIMIT 9223372036854775807 列' where 子句中的 ModularPageID' 不明确
【问题讨论】:
-
我更新了我的问题
-
什么是
MultiClassGrid?为什么所有的 DataObjects 都具有相同的 has_one 定义?只有MP_Section应该有'ModularPage' => 'ModularPage',就这样?在页面上,你可能真的需要在 has_many 中的'Sections' => 'MP_Section',就是这样...... -
谢谢,没用的 $has_one 关系是个愚蠢的错误。 MultiClassGrid 是一个扩展“GridFieldConfig”的类,以便我可以重用相同的配置
标签: silverstripe