我对Symfony还比较陌生,正在尝试安装一个第三方的bundle,它可以读取RSS feeds并将它们插入到数据库中。我要使用的第三方bundle名叫rss-atom-bundle。
阅读了说明后,我可以获取RSS feeds,但由于我对Symfony的知识不足,无法将其插入到数据库中。
这是我拥有的控制器,它可以获取feeds并应该将其插入到数据库中。
我没有看到任何错误,也没有在我的数据库表中看到任何源。这里是文档的
阅读了说明后,我可以获取RSS feeds,但由于我对Symfony的知识不足,无法将其插入到数据库中。
这是我拥有的控制器,它可以获取feeds并应该将其插入到数据库中。
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');
}
}
我没有看到任何错误,也没有在我的数据库表中看到任何源。这里是文档的
readFeed()
方法,它应该将源插入数据库。我已经按照它的步骤进行了操作,但仍然没有成功。这是我的Feed
实体。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.
}
}
我真的希望能得到正确方向上的帮助,因为此时我真的一无所知。
$reader->readFeed($url, $feeds, $date);
添加到数据库中。 - Saadiafeed
实体持久化到数据库中。因此,我认为您需要修复此错误。 - Vadim Ashikhman