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

Default data structures on build


Reply


3 Posts   1267 Views

Avatar
Hamish

Community Member, 712 Posts

18 February 2009 at 4:41pm

Hi all,

Is it possible to provide a set of sample data (ie, as yml) that will automatically be loaded on dev/build? The test runner does this, just wondering if it is possible for normal projects.

This would be great for populating certain objects when the database is built.

Avatar
ajshort

Community Member, 244 Posts

18 February 2009 at 5:54pm

requireDefaultRecords() is run on each DataObject when the DataObject is built - so you could just do something like:

public function requireDefaultRecords() {
   if(!DataObject::get_one('PageType')) {
      $pageType = new PageType();
      
      // ...
      
      $pageType->write();
   }
}

Avatar
Hamish

Community Member, 712 Posts

18 February 2009 at 9:25pm

Cheers AJ, that's the sort of thing I'm looking for.