17488 Posts in 4473 Topics by 1978 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1171 Views |
-
Multiple Dynamic Page Create & Saving Relationship Objects

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?
Eg:
$newPage->Title = "New Page 1";
$newPage->someObject = new customDataObject();
$newPage->write();But the 'someObjectID' in the generated page is always zero.
Clues?
Cheers.
-
Re: Multiple Dynamic Page Create & Saving Relationship Objects

11 September 2008 at 4:40pm Last edited: 11 September 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";
$someObject->write();
$newPage->someObjectID = $someObject->ID
$newPage->write(); -
Re: Multiple Dynamic Page Create & Saving Relationship Objects

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.
Cheers.
| 1171 Views | ||
|
Page:
1
|
Go to Top |


