Jump to:

7937 Posts in 1537 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » ParentID not needed... Maybe?

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1 2
Go to End
Author Topic: 2515 Views
  • UncleCheese
    Avatar
    4085 Posts

    Re: ParentID not needed... Maybe? Link to this post

    How do you have your headings set up in your DOM instance?

  • X10D3
    Avatar
    Community Member
    10 Posts

    Re: ParentID not needed... Maybe? Link to this post

    I got it working! Here's what I have...

    HOMEPAGE

    class HomePage extends SiteTree
    {
       public static $db = array();
       public static $has_one = array();   
       public static $has_many = array(
          'Rotator' => 'RotatorImg'
       );   
          
       function getCMSFields()
       {
          $fields = parent::getCMSFields();
          
          $fields->addFieldToTab("Root.Content.Rotator", new DataObjectManager(
             $this,
             'Rotator',
             'RotatorImg',
             array(
                'RotAlt' => 'Image Alt Text',
                'RotTitle' => 'Link Title',
                'ReturnRotEnabledYesNo' => 'Enabled',
                'ReturnRotWindowYesNo' => 'New Window',
                'Thumbnail' => 'Preview'
             ),
             'getCMSFields_forPopup'
          ));
          return $fields;
       }

    ....

       function GetRotator()
       {
          return DataObject::get('RotatorImg', "RotEnabled = 1", "SortOrder", "", "", "DataObjectSet");
       }

    ...
    }

    OBJECT

    class RotatorImg extends DataObject
    {
       static $db = array(
          'RotLink' => 'Text',
          'RotAlt' => 'Text',
          'RotTitle' => 'Text',
          'RotWindow' => 'Boolean',
          'RotEnabled' => 'Boolean'
       );
       
       static $has_one = array(
          'HomePage' => 'HomePage',
          'RotImage' => 'Image'
       );
       
       function getCMSFields_forPopup()
       {
          return new FieldSet(
             new TextField('RotAlt', "Rotator Image Alt Text"),
             new TextField('RotTitle', "Rotator Link Title"),
             new TextField('RotLink', "Rotator Link"),
             new CheckboxField('RotWindow', 'Open in new window?'),
             new CheckboxField('RotEnabled', 'Display on Website?'),
             new ImageField('RotImage', "Rotator Image")
          );
       }
       
       function Thumbnail()
       {
          if ($this->RotImage())
             return $this->RotImage()->CroppedImage(100,100);
          else
             return null;
       }
       
       function ReturnRotEnabledYesNo()
       {
          if ($this->RotEnabled)
             return "Yes";
          else
             return "No";
       }
       
       function ReturnRotWindowYesNo()
       {
          if ($this->RotWindow)
             return "Yes";
          else
             return "No";
       }
    }

  • X10D3
    Avatar
    Community Member
    10 Posts

    Re: ParentID not needed... Maybe? Link to this post

    Anything you see that I should be doing different. I have only been working with Silverstripe for about a week. So bare with me

    2515 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.