Jump to:

22997 Posts in 11853 Topics by 2828 members

General Questions

SilverStripe Forums » General Questions » getTitle - Undefined property: Page::$Title

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: 259 Views
  • Andre
    Avatar
    Community Member
    125 Posts

    getTitle - Undefined property: Page::$Title Link to this post

    Hi, I have notied some strange behaviour within Silverstripe 3.1

    I created some kind of Translation for a Page the following way:

    class Page extends SiteTree {

       private static $db = array(
    'Title_en' => "Varchar(255)",
    'Content_en' => "HTMLText"
       );

    public function getTitle(){
    if(i18n::get_locale() == 'de_DE'){
    return $this->Title;
    }else{
    return $this->Title_en;
    }
    }

    public function getContent(){
    if(i18n::get_locale() == 'de_DE'){
    return $this->Content;
    }else{
    return $this->Content_en;
    }
    }
    }

    This throws a Notice, as of "$this->Title" isn't known within getTitle(), but why?

    Anyone any Ideas?

  • simon_w
    Avatar
    Forum Moderator
    467 Posts

    Re: getTitle - Undefined property: Page::$Title Link to this post

    This is because PHP stops infinite recursion on magic methods. $this->Title would call $this->getTitle() which would call $this->Title which would call $this->getTitle() and so on.

    Instead, use $this->getField('Title')

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