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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Archive /

Our old forums are still available as a read-only archive.

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

Adding a new page below another page


Go to End


2 Posts   2365 Views

Avatar
infinity

Community Member, 3 Posts

12 December 2008 at 3:36pm

Hi,

I'm adding a new page using a form on the front page (similar to the tutorial for adding a poll result). I got it working to just add the page. What I'd like to do now is add the page below an existing page. Can anybody suggest how I do this.

Here is the current code that just adds the new page at the top of the hierarchy:
function addMyItem($data, $form) {
$my_item = new MyItem();
$form->saveInto($my_item);
$my_item->write();

Director::redirectBack();
}

Thanks,
Bruce

Avatar
infinity

Community Member, 3 Posts

12 December 2008 at 4:02pm

I've figured out how to do this:

function addMyItem($data, $form) {
$my_items_holder_set = DataObject::get('MyItemsHolder');
$my_items_holder = $my_items_holder_set->First();
$my_item = new MyItem();
$form->saveInto($my_item);
$my_item->setParent($my_items_holder);
$my_item->write();

Director::redirectBack();
}