dsf22567 2013-09-25 13:55
浏览 36
已采纳

无法让第三方应用程序验证xml提要?

I'm currently trying to create a feed which will be automatically updated and then use a service like twitterfeed to then push these changes to facebook and twitter.

When I view www.mysite.com/rss I see all of the correct jobs displayed in plain text and not in a hierarchical format but I don't have any other errors to really tell you.

I am using codeigniter and this is the current code which I have within my controller and view.

controller:

public function index(){

    $data['encoding'] = 'utf-8'; 
    $data['feed_name'] = 'www.mysite.com'; 
    $data['feed_url'] = 'http://www.mysite.com/rss'; 
    $data['page_description'] = 'Welcome to www.mysite.com feed url page'; 
    $data['page_language'] = 'en'; 
    $data['creator_email'] = 'myname@mysite.com'; 

    $this->db->order_by('time', 'DESC');
    $data['jobs'] = $this->db->get_where('jobs', array('active' => 1))->result_array(); 

    header("Content-Type: application/rss+xml"); 

    $data['main_content'] = "rss"; 
    $this->load->view('templates/rss_template', $data);

}

view:

<?php echo '<?xml version="1.0" encoding="UTF-8"?>'; ?>

<rss version="2.0"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:admin="http://webns.net/mvcb/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:content="http://purl.org/rss/1.0/modules/content/">       

    <channel>

    <title><?php echo $feed_name; ?></title>
    <link><?php echo $feed_url; ?></link>
    <description><?php echo $page_description; ?></description>
    <dc:language><?php echo $page_language; ?></dc:language>
    <dc:creator><?php echo $creator_email; ?></dc:creator>
<?php
    foreach($jobs as $job){
?>          
        <item>
            <title><?php echo $job['role']; ?></title>
            <link><?php echo base_url()."job/view/".$job['id']."/".$job['url'].""; ?></link>
            <guid><?php echo date("D, d M Y H:i:s O", $job['time']); ?></guid>
            <description><?php echo strip_tags($job['extract']); ?></description>                                               
        </item> 
<?php           
    }

?>
    </channel>

</rss>
  • 写回答

1条回答 默认 最新

  • dongweicha6077 2013-09-25 14:33
    关注

    The problem may be that you are using the PHP functionheader("Content-Type: application/rss+xml") to set your content type.

    As CodeIgniter does not know you are doing this it too will try and set the Content-Type headder.

    Try using the build in $this->output->set_content_type(); method (docs) instead

    $this->output->set_content_type('application/rss+xml');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮