How to use MagpieRSS with CakePHP

In: Tutorials

23 Jul 2009

MagpieRSS is a PHP based RSS parser that can be downloaded here http://magpierss.sourceforge.net/

What good is it you ask? You can use it to pull in information from any RSS feed and do what ever you want with the data. For example I use it to pull the RSS feed from my blog and display links to my latest posts on http://www.rewardchamp.com You can see it on the bottom of the page.

CakePHP makes this way to easy! First you need to download the MagpieRSS files from the link above and then extract to your vendors folder.

You need to put this line at the very top of your controller file you want to use RSS with. Before the class declaration

App::import('Vendor','Snoopy', array("file" => "magpierss/extlib/Snoopy.class.inc"));

Now inside a function you want create a new Snoopy object. I use Snoopy because I’m lazy … MagpieRSS is not constructed as Classes like CakePHP would like it to be … Snoopy is. Snoopy will return XML for you which you can make into an easily usable object with SimpleXMLElement. You can var_dump to see what exactly is in this object. You can figure out what to do from there.

$snoopy = new Snoopy();
$snoopy->fetch('http://www.solitechgmbh.com/your/feed/here');
$xml = new SimpleXMLElement($snoopy->results);
return $xml->channel->item;

Something like this will get you the title for example.

echo $item->title;

Happy coding!

1 Response to How to use MagpieRSS with CakePHP

Avatar

Korbi Brav

July 25th, 2009 at 9:07 am

Thanks, works great.

Comment Form

SoliTech GmbH

Services such as Facebook, MySpace, LinkedIn, Twitter etc. are experiencing exponential growth. Your company needs to stay competitive and utilize this new technology. We will help you devise and execute a higly effective marketing strategy that will grow your brands' following and deliver measurable results.

Click here to see all our service.

RSS What’s new in the forums?

  • EP not recovering again March 9, 2010
    Is this a regular thing? Its happened twice in my time on this game […]
  • Mito story competition. March 2, 2010
    This is a competition for the 11th Chapter of our little ninjas life! Please come up with something that follows the over all story line as stated... […]
  • Ninja News March 2, 2010
    Could we add another "news" type bar, like what appears when you kill someone, with perhaps forum news and maybe updates on things like server... […]
  • Arena February 18, 2010
    I was thinking about adding a new area, where there is no hiding and everyone can fight. […]