Jump to:

23486 Posts in 18995 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Populating Default Records in SS3 Page Types

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

Page: 1
Go to End
Author Topic: 532 Views
  • novaweb
    Avatar
    Community Member
    115 Posts

    Populating Default Records in SS3 Page Types Link to this post

    Greetings,

    In SS2 we used public static $default_records with a nested array to populate the default records we wanted upon page creation.

    In SS3, looking through SiteTree, I assumed this was now just static $defaults, however this only populates the URLSegment... not the Title etc.

    http://sspaste.com/paste/show/512586ed32e22

    Anyone know?

    Cheers!

  • Mojo5000
    Avatar
    Community Member
    5 Posts

    Re: Populating Default Records in SS3 Page Types Link to this post

    I know the post is kind of old, but here is an example, not sure if it answers your Q.

    In your Page class:

    function requireDefaultRecords() {
    if(class_exists('MyPage') && !DataObject::get_one('MyPage')) {
    $page = new WeaponsPage();
    $page->Title = 'My Page';
    $page->URLSegment = 'mypage1';
    $page->Status = 'Published';
    $page->Sort = 2;
    $page->write();
    $page->publish('Stage', 'Live');
    $page->flushCache();
    DB::alteration_message('MyPage created.', 'created');
    }
    }

    532 Views
Page: 1
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.