无法配置Symfony(第三方)包
问题描述:
我是Symfony的新手,我试图设置第三方包来读取RSS源,然后将它们插入到数据库中。我想使用第三方束被称为rss-atom-bundle无法配置Symfony(第三方)包
阅读说明我能得到RSS提要但是我不能将它们插入到数据库后大概是由于我缺乏的Symfony
这方面的知识的是控制器我有获取的饲料,然后应插入到数据库
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()
方法的documentaion,它应该将数据源插入数据库。我跟了,但还没有成功
这是我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.
}
}
我会很感激在正确的方向上推,因为我在这一点上真的毫无头绪。
答
我还没有试过这种捆绑,但我认为你需要告诉您要新创建的饲料保存到数据库中学说:
$feeds = new Feed;
$reader->readFeed($url, $feeds, $date);
$em = $this->getDoctrine()->getManager();
$em->persist($feeds);
$em->flush();
return $this->render('default/index.html.twig');
UPDATE
按照文档如果您想使用doctrine
将订阅源及其项目保存到数据库中,则需要创建两个分类,一个用于FeedInterface
,另一个用于ItemInInterface
和ItemOutInterface
。此外,您需要为这些类配置doctrine数据库模式,以便知道如何将数据存储在数据库中。接下来,您需要告诉该软件包使用您的课程,并最终致电persist()
和flush()
以实际上将供稿及其项目保存到数据库中。
恐怕不会导致列xyz的错误不能为空,我提取的提要应该使用'$ reader-> readFeed($ url,$ feeds,$ date)添加到数据库中;'根据文档 – Saadia
所以你得到一个错误?将此错误消息插入问题中。 –
不,我没有收到错误,当我运行该操作时,我说错误发生在我应用您的解决方案时 – Saadia