Jump to:

23550 Posts in 19336 Topics by 2890 members

General Questions

SilverStripe Forums » General Questions » DataObject::Get no success

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: 1178 Views
  • tomklang
    Community Member
    6 Posts

    DataObject::Get no success Link to this post


    In my Tree I have News Section (Type:News) with some Childs (Type:ArticlePage)...

    What I want to do is listing some news in the News-Page.

    Is the following function within the controller section of the news.php the right approach?
    First get the parent ID and then the child infos?

    function LatestNews($num=3) {
    $news = DataObject::get_one("News");
    return ($news) ? DataObject::get("ArticlePage", "ParentID = $news->ID", "Date DESC", "", $num) : false;

    When I control the function the result (e.g. $Title) is empty...


  • banal
    Community Member
    901 Posts

    Re: DataObject::Get no success Link to this post

    Hi there

    That looks fine to me. You could even ditch the part where you get the parent, since you're already in the parent?

    function LatestNews($num = 3){
       return DataObject::get('ArticlePage', 'ParentID = ' . $this->ID, 'Date DESC', '', $num);

    How does your template code look like?

  • tomklang
    Community Member
    6 Posts

    Re: DataObject::Get no success Link to this post



    Template code is quite easy:
    <% control LatestNews %>
    <% end_control %>

    What would be interesting is the question how
    one can add additional filter criteria like:

    Show only childs from number 3 to e.g. number 6
    what can I use to access just one child directly...(show only child number 5)

    thanks for your ideas...

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.