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

getTitle - Undefined property: Page::$Title


Go to End


2 Posts   2122 Views

Avatar
Andre

Community Member, 146 Posts

7 October 2013 at 7:40am

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?

Avatar
(deleted)

Community Member, 473 Posts

7 October 2013 at 8:40am

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