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

Inherit data from parent?


Go to End


2 Posts   1313 Views

Avatar
Rawbit

Community Member, 52 Posts

14 March 2009 at 7:30am

Let's say I have a Page (Page class) called Susan. On this page is a tab called 'Favorites' and on that tab, is a text field called 'Favorite song'.

What I want to achieve, is that when a subpage is created under Susan, say page 'Donna', Donna inherits Her parents favorite song but can later change this.

Ideas?

Avatar
Carbon Crayon

Community Member, 598 Posts

14 March 2009 at 10:02am

Edited: 14/03/2009 10:03am

Hi Rob

If you are using 2.3 then you can use the onAfterWrite() function in your page model. Something like this should work:

function onAfterWrite() {
                  parent::onAfterWrite();
$this->FavouriteSong = $this->Parent()->FavouriteSong;
	}