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.

General Questions

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

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

Inherit data from parent?


Reply

2 Posts   817 Views

Avatar
Rawbit

14 March 2009 at 7:30am Community Member, 52 Posts

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

14 March 2009 at 10:02am (Last edited: 14 March 2009 10:03am), Community Member, 598 Posts

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;
   }