2010-11-25 71 views
0

我正在嘗試在Symfony中創建一個RSS提要。在Symfony中創建一個RSS提要

我已經添加了以下路線:

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

我創建了一個名爲indexSuccess.rss.php模塊/內容/模板/文件:

test message 

但是,當我轉到url mysite/rss,我得到的只是一個空白頁面!根本沒有內容,甚至沒有調試工具欄...幫助!到底是怎麼回事 ?

回答

3

我和你有同樣的問題。我注意到,sf_format: xmlindexSuccess.xml.php似乎只要你喜歡上指定的RSS XML標籤的工作:

<?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

這是一個黑客,但我看不出怎麼回事辦呢。

+0

迴應「sf_format:xml」訣竅! – Manu 2010-11-25 13:40:30

3

默認情況下,RSS格式不通過symfony應用程序的支持,但你可以添加這些行你factories.yml

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

$sf_format = rss所有請求將通過與Mime類型application/rss+xml

-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 %} 
+0

你可以添加一些解釋嗎? – 2017-09-15 16:09:48