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

Populating Default Records in SS3 Page Types


Reply


2 Posts   631 Views

Avatar
novaweb

Community Member, 115 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');
}
}