Jump to:

23486 Posts in 18995 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Inherit data from parent?

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

Page: 1
Go to End
Author Topic: 810 Views
  • Rawbit
    Community Member
    52 Posts

    Inherit data from parent? Link to this post

    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.


  • Aram
    Community Member
    598 Posts

    Re: Inherit data from parent? Link to this post

    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() {
    $this->FavouriteSong = $this->Parent()->FavouriteSong;

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.