Jump to:

23370 Posts in 18160 Topics by 2864 members

General Questions

SilverStripe Forums » General Questions » custom getter in Page class?

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: 646 Views
  • martimiz
    Avatar
    Forum Moderator
    1067 Posts

    custom getter in Page class? Link to this post

    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?

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: custom getter in Page class? Link to this post

    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');

  • martimiz
    Avatar
    Forum Moderator
    1067 Posts

    Re: custom getter in Page class? Link to this post

    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

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