Jump to:

3372 Posts in 998 Topics by 712 members

Data Model Questions

SilverStripe Forums » Data Model Questions » How to create & publish a Page with the ORM

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1303 Views
  • stefant42
    Avatar
    Community Member
    14 Posts

    How to create & publish a Page with the ORM Link to this post

    Hi all,

    i attempt to create & publish an Page with the ORM till 5 hours now. The Problem i see, is the versioning. I can't find a Dokumentation of this SS Part. Now, i need help.

    My Code Snippet :

    Referenz extends Page { ... }

    .....

    ReferenzHolder extends Page {
    .....

    $referenz = new Referenz();                  
    $referenz->ParentID = $this->dataRecord->ID; // ID of ReferenzHolder
    $referenz->Title = $data['Title'];
    $referenz->Status = "Published"
    $referenz->write();
    $referenz->publish('Stage', 'Live');
    ....
    }

    SS creates two Records in SiteTree. One ReferenzHolder and one Referenz. My Questions :

    1. Why SS creates an ReferenzHolder?
    2. Why SS creates the two Records with the Status Attribute "New Page" instead of "Published"?

    If anyone has a link to some Documentions about creating & publishing Pages with ORM, i become relieved.

    Regards,

    Stefan

  • markguinn
    Avatar
    Community Member
    13 Posts

    Re: How to create & publish a Page with the ORM Link to this post

    Stefan,

    I'm not sure about #1. I suspect we may need to see more of your code to figure out why a ReferenzHolder is being created. I think I was having a similar problem to your #2, though, with code that looked pretty similar. Here's what fixed it for me:

    // change this:
    $referenz->write();

    // to this:
    $referenz->writeToStage('Stage');

    Because I was running my code on the frontend side, which was currently in Live mode, the write() call was saving to the live table and then the publish from stage to live was actually overwriting it. This way, it correctly saves to the Stage table, then publishes from Stage to Live.

    Hope that helps,
    Mark

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