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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

custom getter in Page class?


Go to End


3 Posts   1582 Views

Avatar
martimiz

Forum Moderator, 1391 Posts

1 November 2011 at 10:19am

Does anyone know why, in the Page class using a custom getter like the following will get me a [notice]: undefined property: Page::$MyField):

static $db = array ('MyField' => 'Varchar(255)');

function getMyField() {
return $this->MyField;
}

While I can do so on existing SiteTree::$db fields without any problem?

function getContent() {
return $this->Content;
}

Must be something stupid I'm missing?

Avatar
Willr

Forum Moderator, 5523 Posts

1 November 2011 at 9:07pm

Well for one, you shouldn't do that, as $this->Content will call getContent() before your db field. If you want the object then use $this->dbObject('MyField');

Avatar
martimiz

Forum Moderator, 1391 Posts

2 November 2011 at 12:39am

Thanks willr! OK, so I'm glad I didn't really use it anywhere, just tried it out in search of some solution and suddenly got mighty confused :-(

Martine