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.

Data Model Questions /

How to create & publish a Page with the ORM


Reply


2 Posts   1406 Views

Avatar
stefant42

Community Member, 14 Posts

8 December 2009 at 9:47am

Edited: 08/12/2009 9:48am

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

Avatar
markguinn

Community Member, 13 Posts

28 December 2009 at 2:22am

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