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.

Data Model Questions /

[solved] Initialising a DataObject


Reply


5 Posts   514 Views

Avatar
Silverfish

Community Member, 59 Posts

28 November 2011 at 11:20pm

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

Avatar
swaiba

Forum Moderator, 1804 Posts

29 November 2011 at 12:03am

This might help...
http://doc.silverstripe.org/sapphire/en/howto/dynamic-default-fields

Avatar
Willr

Forum Moderator, 5513 Posts

29 November 2011 at 7:37pm

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

Avatar
Silverfish

Community Member, 59 Posts

29 November 2011 at 10:31pm

Hi Willr,

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

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

Regards
Sf

Avatar
Silverfish

Community Member, 59 Posts

3 December 2011 at 12:59am

Edited: 03/12/2011 1:00am

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