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.

DataObjectManager Module

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Using DOM on multiple pages


Go to End
Reply

12 Posts   1843 Views

Avatar
sca123

30 July 2009 at 8:17am Community Member, 61 Posts

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

30 July 2009 at 8:40am Community Member, 271 Posts

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

30 July 2009 at 9:05am Community Member, 61 Posts

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

30 July 2009 at 9:18am Community Member, 271 Posts

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

30 July 2009 at 8:18pm Community Member, 61 Posts

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

Avatar
Martijn

30 July 2009 at 10:36pm Community Member, 271 Posts

Nothing special :)

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

Avatar
UncleCheese

31 July 2009 at 1:17am 4085 Posts

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

31 July 2009 at 1:28am Community Member, 61 Posts

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