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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Data Model Questions /

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

accessing grandparent


Go to End


1809 Views

Avatar
bennettpr

Community Member, 37 Posts

27 March 2009 at 11:20am

Edited: 27/03/2009 11:21am

Hi all,

I have some parent and grandparent checking to do.

Parent checking is as so (in Page model):

function getParent(){
		return ($this->Parent())? $this->Parent()->Title : false;
    }

This works fine.

Grandparent checking is as so (in page model)

function getGrandparent(){
		if($this->Parent()->Parent()){
			return $this->Parent()->Parent()->Title;
		}
		else{
			return false;
		}
    }

Grandparent checking fails with the following error:

"Call to a member function Children() on a non-object "

Now, the class tree should be:
BookHolder -> BookList -> BookPage

I've set up BookList to have BookHolder as a parent, so a call from a bookpage, which sits in a booklist (which belongs to a bookholder) should return the title of the BookHolder page?

Or am I missing something?

Happy to clarify more if required,
Paul