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.

Archive /

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

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

Adding a new page below another page


Reply


2 Posts   1100 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();
}