在SilverStripe 3.1.13中,我试图在由ModelAdmin管理的数据对象之间建立简单的一对多关系。有一个Facility
类可以有一个off的FacilityCategory
我可以进入设施类别选项卡,但一旦我进入设施选项卡,"主"屏幕变成空白,从那时起管理被污染-没有选项卡将显示内容了。
我删除了所有以Facility和FacilityCategories开头的表,并使用flush重复执行dev/build。
有人能告诉我为什么它不起作用吗?我的阶级/关系有什么问题?
Facility.php
class Facility extends DataObject {
private static $db = array(
'Title' => 'Varchar',
);
private static $has_one = array(
'Category' => 'FacilityCategory'
);
public static $summary_fields = array(
'Title', 'Category'
);
public function getCMSFields(){
$fields = FieldList::create(
TextField::create('Title'),
DropdownField::create('FacilityCategoryID', 'Category')
->setSource(FacilityCategory::get()->map('ID', 'Title'))
->setEmptyString('-- select a category --')
);
return $fields;
}
}
class FacilityAdmin extends ModelAdmin {
private static $menu_title = 'Facilities';
private static $url_segment = 'facilities';
private static $managed_models = array(
'Facility'
);
}
FacilityCategory.php
class FacilityCategory extends DataObject {
private static $db = array(
'Title' => 'Varchar'
);
private static $has_many = array(
'Facilities' => 'Facility'
);
public function getCMSFields(){
$fields = FieldList::create(
TextField::create('Title')
);
return $fields;
}
}
class FacilityCategoryAdmin extends ModelAdmin {
private static $menu_title = 'Facility Categories';
private static $url_segment = 'facility-categories';
private static $managed_models = array(
'FacilityCategory'
);
}
可能是在您的$summary_fields
(预计是私有的)中,您列出了相关的类别对象,而不是类别对象上的特定字段,因此有:
private static $summary_fields = array(
'Title',
'Category.Title'
);