It is not so bad rendering RSS feeds from an index.php page I have seen a lot of examples of it. But I am having problems doing it from a class. This is what I have and I am sure I have many errors… PHP is not my strong point so if you could let me know where i am going wrong i would apprecite it…
<?php
class RssDisplay {
protected $fromrss;
protected $allitemscollected_feed;
public function __construct($urllink, $total_items){
$this->fromrss = $urllink;
$this->allitemscollected_feed = $total_items;
}
public function getItems($allitemscollected_feed){
$feed = simplexml_load_file($this->fromrss, $this->allitemscollected_feed);
return $feed;
$collected_items[] =$feed;
$this->set('collected_items', $collected_items);
}
foreach('allitemscollected' as $feed){
$items->title;
$items->pubDate;
$items->description;
}
}
from my index this is what I am doing:
$feed = new RssDisplay('http://feeds.feedburner.com/insidethehall?format=xml');
For starters i would advice you to take a look at Foreach and PHP OPP Basics because
foreachis not in any methodforeach('allitemscollected' as $feed){is not valid becauseforeachfirst argument needs to be array_expressionreturn $feed;was called early which would make other codes invisible$this->set(method those not exists yet it was called$this->set('collected_items', $collected_items);simplexml_load_filesecond argument needs to be a valid class name that extendsSimpleXMLElementyet an integer is passedYour Simple Class you look like this
Output
Grantland previews the Hoosiers
Fri, 02 Nov 2012 19:22:21 +0000
Grantland: College Basketball Team Previews: Indiana There’s no shortage of offensive firepower with the Hoosiers, and the great thing about Tom Crean is that he’s never afraid to use it. Indiana was well inside the top half of the country in tempo last season, and with an extra year of chemistry it’s a good bet […]
Notebook: Creek shines in return from injury
Fri, 02 Nov 2012 02:57:32 +0000
Maurice Creek got off the bench and walked toward the Assembly Hall scorer’s table with just over 11 minutes left in the first half of Thursday night’s exhibition game against Indiana Wesleyan. Creek checked in with the official scorer, then waited patiently for the moment he’s been thinking about for more than 20 months — […]