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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Data Model Questions /

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

Create Child SiteTree under Parent via PHP

Go to End

3 Posts   1807 Views


Community Member, 21 Posts

25 November 2009 at 8:53am


in the Silverstripe CMS Backend, you are able to create new pages using the tree view on the left side.

Now my intention is to create new pages with the use of formular data. Users should be able to create a new page without using the backend.

My first try is:

function doSubmit() {
  $subpage = new Page();
  $subpage->setParent($this); //also tried $subpage->parentID = $this->ID;
  $subpage->Title = ".."; //set attributes

The function is in the Holder of Page and gets called by the form. Page and PageHolder are extended from SiteTree.

My problem is, that after the function was called, there is no new subpage. In the database is only a new entry in "SiteTree", but without any fields filled (all NULL).

Would be nice if someone has a clue what i'm doing wrong or gives a description to create subpages. :)



Forum Moderator, 5523 Posts

25 November 2009 at 11:58am

You were on the right track but save() is incorrect. How I would do that is

function doSubmit() { 
$subpage = new Page(); 
$subpage->ParentID = $this->ID;
$subpage->Title = "Page";

// if you want to publish the page to the site then you will need
$subpage->publish('Stage', 'Live');


Community Member, 21 Posts

25 November 2009 at 9:59pm

Edited: 25/11/2009 9:59pm

Thanks, after a couple hours of sleep it's now working.
The point was the publishing function.

I also found something about creating pages in the recipes:

PS: I used write() - save() was a typing error, sorry ;)