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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

Populating Default Records in SS3 Page Types


Go to End


2 Posts   2570 Views

Avatar
novaweb

Community Member, 116 Posts

21 February 2013 at 4:01pm

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!

Avatar
Mojo5000

Community Member, 5 Posts

19 November 2013 at 4:43pm

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');
}
}