SilverStripe 3.1 - Page creating & publishing from the FrontEnd

核能气质少年 提交于 2019-12-01 11:37:00

ok, a million tries later i got it! :) For everybody else who get stuck on this.

You just need to restore the live page to stage after writing

$page->write();
$page->doRestoreToStage();

That's all :)

Reddragon

Many many thanks for your two lines of codes

$page->write();

$page->doRestoreToStage();

I have been struggling with SiteTree table for a last few days,trying to write a new record to this table.

One important point is never use SiteTree class directly otherwise it won't work

eg $mySiteTree = new SiteTree(); (Bad)

Create a new page extends SiteTree() , say, Mypage

$mypage = new Mypage();
$mypage->Title = 'My Page';
$mypage->URLSegment = 'testing';
$mypage->ShowInMenus = '1';
$mypage->Version = '1';
$mypage->ParentID = '24';
$mypage->write();
$mypage->doRestoreToStage();

Enjoy!!!!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!