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.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

PopulateDefault a DataObjectManager List


Reply

917 Views

Avatar
eceers

14 March 2010 at 12:13pm Community Member, 24 Posts

Hi,

My client has a need to be able to build a DataObjectManager list of default values.

I thought I was going to be able to use something like;

   public static $db = array(
      'TextBox1' => 'Text',
      'TextBox2' => 'Text',
      'TextBox3' => 'Text'      
   );
   
   public static $has_many = array(
      'ProjectFields1' => 'ProjectField'
   );
   
   public function populateDefaults() {
       $this->TextBox1 = 'Eggs Are Great';
       $this->TextBox2 = 'Patty is a winner';
      $this->TextBox3 = 'Maya steps very loudly';
      
      $this->ProjectFields1 = array(
         array(
            'Title'=>'Question 01',
            'Description'=>'Lorem ipsum dolor sit amet, consectetur adipisicing elit.'
            ),
         array(
            'Title'=>'Question 02',
            'Description'=>'Lorem ipsum dolor sit amet, consectetur adipisicing elit.'
            )   
         );   
    parent::populateDefaults();
   }

but no luck :(

The DataObject I'm using looks like

class ProjectField extends DataObject {

   static $db = array(
      'Title' => 'Text',
      'Description' => 'HTMLText',
   );

   static $has_one = array(
       'ProjectField' => 'GeneralPage',
   );

   function getCMSFields_forPopup() {
      $fields = new FieldSet();
      $fields->push( new TextField( 'Title' ) );
      $fields->push( new SimpleWysiwygField('Description'));
      return $fields;
   }   
}

Two questions I suppose, am I heading in the right direction? if so could possibly help me over the edge?

Second, is it all possible? I would of thought so.

Any help would be greatly appreciated.