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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

DataObject::Get no success


Go to End


3 Posts   1723 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
bummzack

Community Member, 904 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