dsf22567
dsf22567
2013-09-25 13:55

无法让第三方应用程序验证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 dongweicha6077 8年前

    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');
    
    点赞 评论 复制链接分享