Jump to:

23478 Posts in 18941 Topics by 2878 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: 1169 Views
  • tomklang
    Avatar
    Community Member
    6 Posts

    DataObject::Get no success Link to this post

    Hi!

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

    Thanks,
    tom

  • banal
    Avatar
    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
    Avatar
    Community Member
    6 Posts

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

    Hi,

    thanks!

    Template code is quite easy:
    <% control LatestNews %>
    $Title
    $Content
    <% 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
    or
    what can I use to access just one child directly...(show only child number 5)

    thanks for your ideas...
    tom

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