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

DataObject::Get no success


Reply


3 Posts   1252 Views

Avatar
tomklang

Community Member, 6 Posts

25 February 2010 at 1:28am

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

Avatar
banal

Community Member, 901 Posts

25 February 2010 at 1:43am

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?

Avatar
tomklang

Community Member, 6 Posts

25 February 2010 at 1:58am

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