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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

[Solved] Changing the classname when saving?


Go to End


2 Posts   1872 Views

Avatar
esakrielaart

Community Member, 59 Posts

25 September 2012 at 12:57am

Hi all,

I have a Class which is extended a few times, now when I use GridField, I use this to add a new holder for this class. Next, I wish the user to select one of the childclasses, as depending on that choice, the fields in the CMS should change to the proper CMSFields (using the corresponding getCMSFields()), however I receive errors at line x of core/Object.php when I simply put $this->class = [selected classname] in my onBeforeWrite. Am I missing some more clever feature of silverstripe to fix this, or is it not possible to change the classname of an object during save? I noticed Object->class is public, so I should just be allowed to overwrite this property right?

Friendly regards,
Maurice

Avatar
esakrielaart

Community Member, 59 Posts

25 September 2012 at 1:43am

Never mind, overlooked the DataObject->setClassName(string) method.

Regards,