Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, Ed, biapar, Willr, Ingo, swaiba

Using DOM on multiple pages


Go to End


12 Posts   3140 Views

Avatar
sca123

Community Member, 61 Posts

30 July 2009 at 8:17am

I have integrated DOM as a template and it is working - however, if I use the same template on another page and go to upload records via the DOM CMS, all of records ever added show except for just the records associated to that page.

How do I setup unique DOM instances on a per page basis (rather than a template basis)

Thanks in advance.

Avatar
Martijn

Community Member, 271 Posts

30 July 2009 at 8:40am

Do you have a $has_one relation for the dataobject with its parent page like?

class MyDataObject extends DataObject{
static $has_one = array (
'ParentPageClass' => 'ParentPageClass'

);

Avatar
sca123

Community Member, 61 Posts

30 July 2009 at 9:05am

Thanks for your advice - I did what I thought to try but just got a redeclare error. My code is as follows, any further assistance would be appreciated.

HomePage.php (uses DOM)

class HomePage extends Page
{
static $has_many = array (
'InfoBoxes' => 'InfoBox'
);

static $has_one = array(
);

public function getCMSFields()
{
$f = parent::getCMSFields();
$manager = new DataObjectManager(
$this, // Controller
'InfoBoxes', // Source name
'InfoBox', // Source class
array('Title' => 'Title', 'Description' => 'Description', 'Link' => 'Link', 'Image' => 'Image'), // Headings
'getCMSFields_forPopup' // Detail fields function or FieldSet

);

$f->addFieldToTab("Root.Content.InfoBoxes", $manager);

return $f;

}

MultiBox Template (needs to also have unique DOM instances for each page use)

static $has_many = array (
'InfoBoxes' => 'InfoBox'
);

function getCMSFields(){
$fields = parent::getCMSFields();

$manager = new DataObjectManager(
$this, // Controller
'InfoBoxes', // Source name
'InfoBox', // Source class
array('Title' => 'Title', 'Description' => 'Description', 'Image' => 'Image'), // Headings
'getCMSFields_forPopup' // Detail fields function or FieldSet
);

$fields->addFieldToTab("Root.Content.InfoBoxes", $manager);
$fields->addFieldToTab("Root.Content.Main", new ImageField('TopImage'));
$fields->addFieldToTab("Root.Content.Banners", new HTMLEditorField('BannerArea'));

return $fields;

}

Class InfoBox

class InfoBox extends DataObject
{
static $db = array (
'Title' => 'Text',
'Description' => 'Text',
'Link' => 'Text'
);

static $has_one = array (
'HomePage' => 'HomePage',
'Image' => 'Image'
);

public function getCMSFields_forPopup()
{
return new FieldSet(
new TextField('Title'),
new TextField('Description'),
new TextField('Link'),
new ImageField('Image')
);
}
}

Avatar
Martijn

Community Member, 271 Posts

30 July 2009 at 9:18am

This seems Double:

MultiBox Template (needs to also have unique DOM instances for each page use)

static $has_many = array (
'InfoBoxes' => 'InfoBox'
);

function getCMSFields(){
$fields = parent::getCMSFields();

$manager = new DataObjectManager(
$this, // Controller
'InfoBoxes', // Source name
'InfoBox', // Source class
array('Title' => 'Title', 'Description' => 'Description', 'Image' => 'Image'), // Headings
'getCMSFields_forPopup' // Detail fields function or FieldSet
);

$fields->addFieldToTab("Root.Content.InfoBoxes", $manager);
$fields->addFieldToTab("Root.Content.Main", new ImageField('TopImage'));
$fields->addFieldToTab("Root.Content.Banners", new HTMLEditorField('BannerArea'));

return $fields;

}

Avatar
sca123

Community Member, 61 Posts

30 July 2009 at 8:18pm

Hi there, sorry to be stupid but I'm not sure what you are saying??!?!

Avatar
Martijn

Community Member, 271 Posts

30 July 2009 at 10:36pm

Nothing special :)

Just that you have the part that I copied twice in your code...

Avatar
UncleCheese

Forum Moderator, 4102 Posts

31 July 2009 at 1:17am

Yeah what is this?

MultiBox Template (needs to also have unique DOM instances for each page use)

static $has_many = array (
'InfoBoxes' => 'InfoBox'
);

Avatar
sca123

Community Member, 61 Posts

31 July 2009 at 1:28am

Sorry but as a Newbie I am confused what is being asked. I'm not sure if it will help but refering to the code above, these are what I currently have:

> HomePage.php - class related to the HomePage template which uses the DOM module (successfully)
> InfoBox.php - class defining the fields required for each InfoBox of which there are multiple (InfoBoxes) - UncleCheese, I think this is the answer to your question?

What I need to do is also use the DOM module for template MultiBox, which has class MultiBox.php. However, each page using this template needs to have unique DOM module based data.

The code attached above shows the code I am trying to use for MultiBox, however at present this is bringing in the DOM data entered via the CMS for HomePage.

Any further help would be appreciated.

Go to Top