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 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

Programatically creating a new page - not quite working

Go to End

4 Posts   3158 Views


Community Member, 49 Posts

12 September 2011 at 2:44pm

I'm writing this code to import a bunch of blog entries from a csv file. I'm just having a wee problem writing the record to the database - It's not creating the SiteTree database record... it is however creating everything else ie. the SiteTree_Versions and SiteTree_Live records, Page and BlogEntry records. I can click the restore action in the CMS which seems to create the SiteTree record but I don't want to have to do that for 200 entries!

Do I need to call some other method or something on $page to insert the regular SiteTree record?

$page = new BlogEntry;

$page->Title = 'testing';
$page->MenuTitle  = 'testing';
$page->Content = 'testing';
$page->URLSegment = 'testing';
$page->ParentID  = 16;
$page->ProvideComments = 1;
$page->ClassName  = 'BlogEntry';
$page->Status  = 'Published';


Thanks for any help...

Ryan M.

Community Member, 309 Posts

12 September 2011 at 6:06pm

Try $page->writeToStage('Stage')


Forum Moderator, 1899 Posts

12 September 2011 at 8:52pm

followed by...

$page->publish("Stage", "Live");

...if you want to publish it too


Community Member, 49 Posts

13 September 2011 at 10:35am

Thanks for your help, I ended up finding $page->doRestoreToStage(); which also worked. Cheers!