Jump to:

22984 Posts in 11765 Topics by 2827 members

General Questions

SilverStripe Forums » General Questions » Programatically creating a new page - not quite working

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

Page: 1
Go to End
Author Topic: 1127 Views
  • SheaDawson
    Avatar
    Community Member
    45 Posts

    Programatically creating a new page - not quite working Link to this post

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

    $page->write();

    Thanks for any help...

  • Ryan M.
    Avatar
    Community Member
    309 Posts

    Re: Programatically creating a new page - not quite working Link to this post

    Try $page->writeToStage('Stage')

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

    Re: Programatically creating a new page - not quite working Link to this post

    followed by...

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

    ...if you want to publish it too

  • SheaDawson
    Avatar
    Community Member
    45 Posts

    Re: Programatically creating a new page - not quite working Link to this post

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

    1127 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.