Jump to:

23450 Posts in 18899 Topics by 2877 members

General Questions

SilverStripe Forums » General Questions » Limiting RSS output results

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: 911 Views
  • kevino
    Avatar
    Community Member
    30 Posts

    Limiting RSS output results Link to this post

    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!

  • dalesaurus
    Avatar
    Community Member
    283 Posts

    Re: Limiting RSS output results Link to this post

    $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

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