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.

What’s new in the forums?

  • New idea for the Toplist :D July 31, 2010
    OK, i was thinking about something... A top list inside of a clan. Im not sure where it would go though, maybe another tab with the clan name, view... […]
  • Add clan invites July 21, 2010
    I think we should bring back the option of add ninja to clan that way we can send invites to people. […]
  • Mass leveling system needs fixing July 20, 2010
    I know the mass leveling system has gotten to be a huge part of a ninja's life now, with the exp coming to us so easily, and the leveling coming just... […]
  • Transferring, fixed. July 20, 2010
    The transfer system greatly unbalanced the game, especially near the end (yet again im sorry for that), but would be it be possible to have it come... […]
  • Useless Clans July 16, 2010
    Clone Troopers Size: 0 Clone Troopers Size: 0 The Sereitei Size: 0 Empire […]
  • An item?...From a Ninja? July 16, 2010
    The title may confuse you on what i really mean, but i was thinking, is there a possibility that you could obtain items from killing other ninjas? it... […]
  • DP July 16, 2010
    I have been playing DuelingNinjas for a long time....and i still dont understand how the DP of armors are taken away. I can have 2bil health, yet... […]
  • Commas??? July 15, 2010
    I think it would be a lot easyer for ninjas these days if the levels, xp, yen, and hp had commas to divide the hundreds thousands and millions.... […]