Jump to:

23581 Posts in 19403 Topics by 2893 members

General Questions

SilverStripe Forums » General Questions » I am having trouble getting the children of a Parent.Parent

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: 873 Views
  • zim
    Avatar
    Community Member
    135 Posts

    I am having trouble getting the children of a Parent.Parent Link to this post

    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'

  • zenmonkey
    Avatar
    Community Member
    528 Posts

    Re: I am having trouble getting the children of a Parent.Parent Link to this post

    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.

  • zim
    Avatar
    Community Member
    135 Posts

    Re: I am having trouble getting the children of a Parent.Parent Link to this post

    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.

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