reza abbasi reza abbasi - 7 months ago 31
PHP Question

Using SimplePie feed parser in Laravel

I tried to use the SimplePie feed parser in Laravel. I pushed autoloader.php and library folder of SimplePie in the Laravel libraries folder, then I added a map for SimplePie in start.php

// folder tree


  • libraries/


    • simple/

      • library/

        • SimplePie/

        • SimplePie.php


      • autoloader.php





// start.php map

Autoloader::map(array(
'Base_Controller' => path('app').'controllers/base.php',
'SimplePie' => path('app').'libraries/simple/autoloader.php',
));


// new object of simplepie

$feed = new SimplePie();
$feed->set_feed_url($feed_url);
$feed->enable_cache(false);
$feed->set_output_encoding('utf-8');


When I create a new object from SimplePie I see this error:

Message:

Autoloader not registered properly

I used this tutorial: http://toolspot.org/read-rss-atom-feed.php

Answer

I'm not familiar with Laravel, but the SimplePie install instructions tell you to put the php and cache directories in the root.

"In your root directory, if they don't already exist, create two folders: php and cache."

Try putting them there instead of nested like you have them. The error message means that SimplePie can't find the class files, so it's a path issue. I would also just stick to the "php" directory instead of creating one called "simple". You might be able to change the directory names in SimplePie somewhere if you want to try and modify their code.