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:

Archive /

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

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

Multiple Dynamic Page Create & Saving Relationship Objects

Go to End

3 Posts   1799 Views


Community Member, 712 Posts

11 September 2008 at 3:18pm

Two issues, both which I thought should be straight forward.

1. I'm trying to create an import data function.

I've added a field in the CMS where the user can enter data. On saving the page, the onBeforeWrite function finds that data and attempts to create sub pages based on what was entered.

However, it seems that writing a page in the onBeforeWrite of another page stops the rest of the page creations, and stops and javascript execution.

Anyone have an idea why this is happening, or have a better method?

2. This one is really dumb, but in the same script, I'm trying to add other objects to the pages that I'm creating. The new page is a subclassed object with two has_one relationships. How can I add these objects while I'm saving these generated pages?


$newPage->Title = "New Page 1";
$newPage->someObject = new customDataObject();

But the 'someObjectID' in the generated page is always zero.




Forum Moderator, 5523 Posts

11 September 2008 at 4:40pm

Edited: 11/09/2008 4:41pm

Im not sure how you have done it but it would seem to me as a wee bit recursive eg on before writing this write X but if X is the same page type as the first one then does that call onBeforeWrite and does that go off and create an object which calls that same onBeforeWrite.. and so on and so on......

Also if thats not the case make sure in your onBeforeWrite you call parent::onBeforeWrite() so that everything else works.

For #2 try this

$newPage->Title = "New Page 1"; 
$someObject = new customDataObject(); 
$someObject->Property = "Wow this is a Field on this Object";
$newPage->someObjectID = $someObject->ID


Community Member, 712 Posts

11 September 2008 at 5:06pm

Hey Will, yeah the recursion issue occured to me and I made sure that the parent call was first - although it will be great when onAfterWrite is released - no more problems :)

I've found a much better method, using an InlineFormAction field, calling a controller and a director rule in _config.php. Much better solution - I'll post it publicly tomorrow.