7913 Posts in 1355 Topics by 930 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » Using DOM on multiple pages
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
| Go to End | Next > | |
| Author | Topic: | 1535 Views |
-
Using DOM on multiple pages

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.
-
Re: Using DOM on multiple pages

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');
-
Re: Using DOM on multiple pages

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')
);
}
} -
Re: Using DOM on multiple pages

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;
}
-
Re: Using DOM on multiple pages

30 July 2009 at 8:18pm
Hi there, sorry to be stupid but I'm not sure what you are saying??!?!
-
Re: Using DOM on multiple pages

30 July 2009 at 10:36pm
Nothing special
Just that you have the part that I copied twice in your code...
-
Re: Using DOM on multiple pages

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'
); -
Re: Using DOM on multiple pages

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.
| 1535 Views | ||
| Go to Top | Next > |


