在Symfony中创建rss源

时间:2010-11-25 10:46:58

标签: rss symfony1

我正在尝试在Symfony中创建RSS源。

我添加了以下路线:

rss_every_content:
  url:    /rss/all
  param: { module: content, action: index, sf_format: rss }
  requirements:
    sf_method: [get]

我在module / content / templates /中创建了一个名为 indexSuccess.rss.php 的文件:

test message

但是当我去url mysite / rss时,我得到的只是一个空页!没有内容,甚至没有调试工具栏......帮助!发生了什么事?

3 个答案:

答案 0 :(得分:3)

我和你有同样的问题。我注意到只要您在顶部指定RSS XML标记,sf_format: xml indexSuccess.xml.php似乎就会起作用:

<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">

<channel>
    <title>RSS Example</title>
    <description>This is an example of an RSS feed</description>
    <link>http://www.domain.com/link.htm</link>
    <lastBuildDate>Mon, 28 Aug 2006 11:12:55 -0400 </lastBuildDate>
    <pubDate>Tue, 29 Aug 2006 09:00:00 -0400</pubDate>

    <item>
        <title>Item Example</title>
        <description>This is an example of an Item</description>
        <link>http://www.domain.com/link.htm</link>
        <guid isPermaLink="false">1102345</guid>
        <pubDate>Tue, 29 Aug 2006 09:00:00 -0400</pubDate>
    </item>

</channel>
</rss>

来自http://www.rss-tools.com/rss-example.htm

这是一个黑客,但我看不出怎么做。

答案 1 :(得分:3)

默认情况下,symfony应用程序不支持RSS格式,但您可以在factories.yml中添加这些行:

all: 
  request:
    param:
      formats:
        rss: application/rss+xml

$sf_format = rss的所有请求都将通过MimeType application/rss+xml

回复

答案 2 :(得分:-1)

Controller Method
//------------------------latest 10 RSS FEED----------------------------------
    public function generateRssFeedsAction()
    {
     $em = $this->getDoctrine()->getManager();
     $newsObj = $em->getRepository('CrossOverAppUserBundle:News')->findlatestNewArticle($page_number=1, $limit=10);
     $response = new Response($this->renderView('CrossOverAppUserBundle:News:rss_feed.xml.twig',array('news'=>$newsObj)));
     $response->headers->set('Content-Type', 'application/xml; charset=utf-8');
     return $response;
    }

Twig Templete 
{% autoescape %}
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    <url>
        {% for entry in news %}
            <article_id>{{ entry.id }}</article_id>
            <article_name>{{ entry.newsTitle }}</article_name>
            <description>{{ entry.newDescription }}</description>
            <article_createdby>{{ entry.user.firstName }}</article_createdby>
            <article_createdat>{{ entry.createdAt|date("d-m-Y H:i:s") }}</article_createdat>
             <article_image><img src="{{ asset(entry.WebPath) }}" width="50" height="50"/></article_image>

        {% endfor %}
    </url>
</urlset>
{% endautoescape %}