Jump to:

3430 Posts in 1057 Topics by 734 members

Data Model Questions

SilverStripe Forums » Data Model Questions » [solved] Initialising a DataObject

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

Page: 1
Go to End
Author Topic: 445 Views
  • Silverfish
    Avatar
    Community Member
    59 Posts

    [solved] Initialising a DataObject Link to this post

    Hi All,

    I'm trying to set some vars on initialising a subclass of a DataObject, i.e.

    class Test extends DataObject { ..

    but if I do

    public function init() { .. }

    it's not called and if I do

    public function Test() {..}

    or

    public function __construct() {..}

    I get an "Undefined Index Error" from sapphire/core/ClassInfo.php

    I guess I'm missing something really stupid but searching the forum and Google didn't help.

    So thanks for any hint!

    Regards
    SF

  • swaiba
    Avatar
    Forum Moderator
    1784 Posts
  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: [solved] Initialising a DataObject Link to this post

    If you call __construct on your data object make sure you call parent::__construct() as well!

  • Silverfish
    Avatar
    Community Member
    59 Posts

    Re: [solved] Initialising a DataObject Link to this post

    Hi Willr,

    didn't I say i miss something stupid? ;)

    Thanks a lot, calling the parent constructor was the point, of course.

    Regards
    Sf

  • Silverfish
    Avatar
    Community Member
    59 Posts

    Re: [solved] Initialising a DataObject Link to this post

    Just wanted to add that it's (obviously) quite important to call the parent constructor with all it's variables, like

    public function __construct($record = null, $isSingleton = false) {

       parent::__construct($record, $isSingleton);
    }


    otherwise it will return empty Objects only ;).

    Regards SF

    445 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.