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

Programatically creating a new page - not quite working


4 Posts   1387 Views


12 September 2011 at 2:44pm Community Member, 46 Posts

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.

12 September 2011 at 6:06pm Community Member, 309 Posts

Try $page->writeToStage('Stage')


12 September 2011 at 8:52pm Forum Moderator, 1796 Posts

followed by...

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

...if you want to publish it too


13 September 2011 at 10:35am Community Member, 46 Posts

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