Hallo somebody,
I have a question about using a DataObject several times on one page with Silverstripe 3.2.1
In my footer i have several boxes with several Items.
I would like to add these several items thru a GridField
So you could have GridField1 for Box1 and GridField2 for Box2 etc.
I made a DataObject FooterText and made a has_one relation to HomePage.
On my HomePage i make several Variables from the DatabaseObject type FooterText.
The problem is that when i put text in one GridField it appears in all of the GridFields.
There is no separation between Blok1, Blok2 etc. it is all one DataObject.
Howe could i fix this?
See my code below
------------------------------------------------
<?php
class FooterText extends DataObject
{
Private static $db = array (
'Title' => 'Varchar',
'URL' => 'Varchar',
);
Private static $has_one = array (
'ConnectionToHomePage' => 'HomePage',
);
public static $summary_fields = array(
'Title' => 'Title'
);
public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->removeFieldFromTab("Root.Main","ConnectionToHomePageID");
$fields->removeFieldFromTab("Root.Main","SortOrder");
return $fields;
}
}
------------------------------------------------
<?php
class HomePage extends Page {
public static $has_many = array(
'Blok1' => 'FooterText',
'Blok2' => 'FooterText',
'Blok3' => 'FooterText',
'Blok4' => 'FooterText'
);
public function getCMSFields() {
$fields = parent::getCMSFields();
$fields-> addFieldToTab('Root.Footer', new GridField('Blok1', 'Footer Blok 1', $this->Blok1(), GridFieldConfig_RelationEditor::create()));
$fields-> addFieldToTab('Root.Footer', new GridField('Blok2', 'Design Tips', $this->Blok2(), GridFieldConfig_RelationEditor::create()));
$fields-> addFieldToTab('Root.Footer', new GridField('Blok3', 'Voorwaarden', $this->Blok3(), GridFieldConfig_RelationEditor::create()));
$fields-> addFieldToTab('Root.Footer', new GridField('Blok4', 'Producten', $this->Blok4(), GridFieldConfig_RelationEditor::create()));
return $fields;
}
}