3069 Posts in 868 Topics by 650 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 267 Views |
-
[solved] Initialising a DataObject

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
it's not called and if I dopublic function init() { .. }
orpublic function Test() {..}
I get an "Undefined Index Error" from sapphire/core/ClassInfo.phppublic function __construct() {..}
I guess I'm missing something really stupid but searching the forum and Google didn't help.
So thanks for any hint!
Regards
SF -
Re: [solved] Initialising a DataObject

29 November 2011 at 12:03am
This might help...
http://doc.silverstripe.org/sapphire/en/howto/dynamic-default-fields -
Re: [solved] Initialising a DataObject

29 November 2011 at 7:37pm
If you call __construct on your data object make sure you call parent::__construct() as well!
-
Re: [solved] Initialising a DataObject

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 -
Re: [solved] Initialising a DataObject

3 December 2011 at 12:59am Last edited: 3 December 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
| 267 Views | ||
|
Page:
1
|
Go to Top |



