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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

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

Limiting RSS output results


Go to End


2 Posts   1235 Views

Avatar
kevino

Community Member, 30 Posts

24 October 2009 at 1:30am

Edited: 24/10/2009 1:32am

I've set up a RestfulService function to output an RSS feed, which works fine.

It's pretty much as described in the documentation here:
http://doc.silverstripe.org/doku.php?id=restfulservice

I've tried to modify the code myself to limit the number of results displayed to 5 instead of the 20 or so which are in the incoming feed.

My code looks like this currently:


	// Accepts an RSS feed URL and outputs a list of links from it
	function RestfulLinks($url){
		$feed = new RestfulService($url);
    $feedXML = $feed->request()->getBody();
    $result = $feed->getValues($feedXML, 'channel', 'item');
    $output = '';
		foreach ($result as $key => $value) {
			// Fix quote encoding
			$description = str_replace('"', '"', $value->description);
			$output .=  '<li><a href="'.$value->link.'">'.$value->title.'</a><br />'.$description.'</li>';
		}
		return $output ->getRange(0,5);
	}

I get the error:

Fatal error: Call to a member function getRange() on a non-object in /mysite/code/Page.php on line 87
(line 87 is the "return $output ->getRange(0,5);")

Can anyone suggest which direction I should be going?

Thanks!

Avatar
dalesaurus

Community Member, 283 Posts

24 October 2009 at 10:02am

$output is a php primitive string type, no such function exists (a string is not an object).

Remove that ->getRange() call, or use an appropriate method for a string if you need to do some kind of formatting. If you only want to first 5 of those use a for($i=0; $i<5;$i++){} loop instead of foreach