Forgive me for such a potentially simple question; it seems like everyone's plugins "of course" know how to do this, but it is stumping me.
I have some code in a controller class that is simply trying to create SS pages and attach them to a parent in the tree. Based on what I find in the forums and API docs, I constructed the following bare-bones test case:
$parentPage = ContentController::Page('home'); // anything $ssPage = new Page(); $ssPage->setParent($parentPage); $ssPage->Title = 'My Test CodeCreated Page'; $ssPage->URLSegment = 'my-test-codecreated-page'; // $ssPage->generateURLSegment($ssPage->Title) works too $ssPage->Content = 'some content'; $ssPage->write(); $ssPage->doPublish(); $ssPage->flushCache();
On the surface, it looks like it works. The page appears on the publicly-viewable site in the proper location, with the expected Title, Content, and url.
But in the CMS things start to go bad. Refreshing the CMS shows the page in what looks like a Deleted state (red, strikeout text). The only action button available is "Restore". And when I click it, I get "Server error". Even after all of that, the public page still views OK. But now I can't edit or delete it. (Well I could delete the appropriate records in the DB, but that's not the point.) :-)
Willr mentioned in one post that the code had to be in the data object. Does that mean the actual lines of code have to be inside the data object, or only that the above methods have to be called on a valid data object?
Thanks for any and all help.