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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

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