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

Programatically creating a new page - not quite working

Go to End

4 Posts   2591 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!