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.

General Questions /

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

I am having trouble getting the children of a Parent.Parent


Reply


3 Posts   941 Views

Avatar
zim

Community Member, 135 Posts

15 July 2011 at 2:25am

I am having trouble getting the children of a Parent.Parent

The structure of the site is as follows.

TOP LEVEL -> has one 'PlayerSites' -> has many -> 'PlayerSite' -> has one -> 'NewsHolder -> has many 'NewsPage'

So on the 'PlayerSite' page I am getting all the 'NewsPage' items displayed in a list using this function in PlayerSite.PHP

public function PlayerVidNews() {
    $playervidnews = DataObject::get_one("PlayerSite");
    return ($playervidnews) ? DataObject::get("NewsHolder", "ParentID=" . $this->ID, "") : false;
   }

..and then

<% control PlayerVidNews %>
         
         <% control Children %>

   <% end_control %>
         
<% end_control %>

What I want to do is click on one of the 'NewsPage' items from 'PlayerSite' page, which goes to a 'NewsPage' page. On this 'NewsPage' page I also want to display a list of all the other 'NewsPage' items that belong to that particular 'PlayerSite'. However I cant seem to get just those 'NewsPage' items that belong to that particular 'Playersite'.

I have tried putting the same function in NewsPage.PHP And NewsHolder.PHP. But this returns nothing or all 'NewsPage' items, regardless of which 'PlayerSite' they belong to.

public function PlayerVidNews() {
    $playervidnews = DataObject::get_one("PlayerSite");
    return ($playervidnews) ? DataObject::get("NewsHolder", "ParentID=" . $this->ID, "") : false;
   }

... can anyone advise how i might get just those 'NewsPage' items that belong to that particular 'PlayerSite'

Avatar
zenmonkey

Community Member, 532 Posts

15 July 2011 at 3:42am

I think you're just looking for the wrong ID.

PlayerSite will have a field called NewsHolderID that identifies which NewsHolder belongs to it, and the NewsPage object will also have a NewsHolderID that identifies which NewsHolder it belongs to.

So on the NewsPage you could look all NewsPage items with NewsHolderID of $this->NewsHolderID (I think)

Without actually seeing the structure of the DataObject its hard for me to visualize. But if you look right at you database you should be able to work it out from the column names.

Avatar
zim

Community Member, 135 Posts

15 July 2011 at 4:52am

Thanks.

this is what i needed. Basic stuff i know. but now i think i will be able to manipulate the data just as i need. I will let you know.