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.

Customising the CMS /

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

[SOLVED] Publishing latest news on the homepage


Go to End


3 Posts   2304 Views

Avatar
clauer

Community Member, 12 Posts

16 January 2009 at 8:54am

Edited: 17/01/2009 10:40am

Hi,

I'm new to SilverStripe and I like the open concept. So I worked through the tutorials and now I'm stuck in tut 2.

To publish the latest news on the homepage, I wrote the following function as described in the tut:

class HomePage_Controller extends Page_Controller {
function LatestNews($num=5) {
$news = DataObject::get_one("NewsHolder");
return ($news) ? DataObject::get("NewsPage", "ParentID = $news->id", "Date DESC", "", $num) : false;
}

}

Now when I address the homepage in the browser I get the error

--> The website server has not been able to respond to your request.

The entry in the Apache access.log looks like this:

--> "GET /SilverStripe/ HTTP/1.1" 500 86

Anyone who can get me on the right way? Thanks in advance.

Christian

Avatar
Willr

Forum Moderator, 5523 Posts

16 January 2009 at 4:50pm

try adding ' ' around the DBField

function LatestNews($num=5) { 
      $news = DataObject::get_one("NewsHolder"); 
      return ($news) ? DataObject::get("NewsPage", "ParentID = '$news->id'", "Date DESC", "", $num) : false; 
}

Next thing you could try is turning the site into 'Devmode' by adding Director::set_environment_type("dev") to your _config.php file or Check your PHP error logs for a clue

Avatar
clauer

Community Member, 12 Posts

17 January 2009 at 10:39am

Thanks, obviously the quotes round the variable name $news->id are missing.
Christian