I am faily new to Symfony and I am trying to setup a third party bundle that reads RSS feeds and then insert them into database. The third party bundle I am trying to use is called rss-atom-bundle
After reading the instructions I can get the RSS feeds however I am not able to insert them into database probably due to my lack of knowledge of Symfony
This is the controller I have that fetches the feeds and then should insert into database
namespace AppBundle\Controller;
use AppBundle\Entity\Feed as Feed;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class DefaultController extends Controller
{
/**
* @Route("/", name="homepage")
*/
public function indexAction()
{
// fetch the FeedReader
$reader = $this->container->get('debril.reader');
// this date is used to fetch only the latest items
$unmodifiedSince = '11/11/2014';
$date = new \DateTime($unmodifiedSince);
// the feed you want to read
$url = 'https://example.com/feed/';
// now fetch its (fresh) content
$feed = $reader->getFeedContent($url, $date);
// in developer tool bar I can see the feeds using dump()
dump($feed);
$items = $feed->getItems();
//Insert fetched feeds into database
$feeds = new Feed;
$reader->readFeed($url, $feeds, $date);
return $this->render('default/index.html.twig');
}
}
I do not see any error and I do not see any feeds inside my database table as well.
Here is the documentaion of the readFeed()
method the which is supposed to insert feeds into database. I have followed it but yet no success
This is my Feed
Entity
namespace AppBundle\Entity;
use Debril\RssAtomBundle\Protocol\FeedInterface;
use Debril\RssAtomBundle\Protocol\ItemIn;
use Doctrine\ORM\Mapping as ORM;
/**
* Feed
*/
class Feed implements FeedInterface
{
/**
* @var integer
*/
private $id;
private $lastModified;
private $title;
private $description;
private $link;
private $publicId;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Atom : feed.entry <feed><entry>
* Rss : rss.channel.item <rss><channel><item>
* @param \Debril\RssAtomBundle\Protocol\ItemIn $item
*/
public function addItem(ItemIn $item)
{
// TODO: Implement addItem() method.
}
public function setLastModified(\DateTime $lastModified)
{
$this->lastModified = $lastModified;
return $this;
}
public function setTitle($title)
{
$this->title = $title;
return $this;
}
public function setDescription($description)
{
$this->description = $description;
return $this;
}
public function setLink($link)
{
$this->link = $link;
return $this;
}
public function setPublicId($id)
{
$this->publicId = $id;
return $this;
}
/**
* Atom : feed.updated <feed><updated>
* Rss : rss.channel.lastBuildDate <rss><channel><lastBuildDate>
* @return \DateTime
*/
public function getLastModified()
{
return $this->lastModified;
}
/**
* Atom : feed.title <feed><title>
* Rss : rss.channel.title <rss><channel><title>
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Atom : feed.subtitle <feed><subtitle>
* Rss : rss.channel.description <rss><channel><description>
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* Atom : feed.link <feed><link>
* Rss : rss.channel.link <rss><channel><link>
* @return string
*/
public function getLink()
{
return $this->link;
}
/**
* Atom : feed.id <feed><id>
* Rss : rss.channel.id <rss><channel><id>
* @return string
*/
public function getPublicId()
{
return $this->publicId;
}
/**
* Atom : feed.entry <feed><entry>
* Rss : rss.channel.item <rss><channel><item>
* @return array[\Debril\RssAtomBundle\Protocol\ItemOut]
*/
public function getItems()
{
// TODO: Implement getItems() method.
}
}
I will really appreciate a push in right direction as I am really clueless at this point.