Silverstripe Version:
Question:
I’m new to silverstripe. I tried to make a property holder that can create Categories. so I added $has_many in PropertyHolder.php, then $has_one, in the CategoryData.php.
then I use AddFieldToTab ot have a new tab to insert the Categories, but when I add new Property holder in the CMS, there’s no Tab for Categories. please help me figure out what I did wrong.
//PropertyHolder.php
class PropertyHolder extends Page
{
private static $allowed_children = [
PropertyPage::class,
];
private static $has_many = [
'Categories'=>CategoryData::class,
];
public function getCMSField()
{
$fields = parent::getCMSField();
$fields->addFieldToTab('Root.Categories', Gridfield::create(
'Categories',
'Property Categories',
$this->Categories(),
GridFieldConfig_RecordEditor::create()
));
return $fields;
}
}
//CategoryData.php
class CategoryData extends DataObject
{
private static $db = [
‘Title’ =>‘Varchar’
];
private static $has_one = [
'PropertyHolder'=>PropertyHolder::class,
];
public function getCMSField()
{
return FieldList::create(
TextField::crete('Title')
);
}
}