Jump to:

23377 Posts in 18296 Topics by 2868 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: 795 Views
  • Rawbit
    Avatar
    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.

    Ideas?

  • Aram
    Avatar
    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() {
    parent::onAfterWrite();
    $this->FavouriteSong = $this->Parent()->FavouriteSong;
       }

    795 Views
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.