Php 在代码点火器中构建RSS提要

Php 在代码点火器中构建RSS提要,php,xml,codeigniter,rss,Php,Xml,Codeigniter,Rss,我想建立一个RSS提要,但我的输出不是真的,如何修复它 我使用本教程:http://www.derekallard.com/blog/post/building-an-rss-feed-in-code-igniter/ 请在下面查看我的完整代码: CI_控制器: function rss_feed($limit = NULL) { $data['encoding'] = 'utf-8'; $data['feed_name'] = 'neginph.com'; $dat

我想建立一个RSS提要,但我的输出不是真的,如何修复它

我使用本教程:http://www.derekallard.com/blog/post/building-an-rss-feed-in-code-igniter/

请在下面查看我的完整代码:

CI_控制器:

function rss_feed($limit = NULL)  
{
    $data['encoding'] = 'utf-8';
    $data['feed_name'] = 'neginph.com';
    $data['feed_url'] = 'http://www.neginph.com';
    $data['page_description'] = 'Mono-calcium phosphate and calcium phosphate producer in the Persian month Dey';
    $data['page_language'] = 'en-en';
    $data['creator_email'] = 'Negin phosphate North';
    $data['posts'] = $this->db->order_by("id", "asc")->get_where('rss_feed', array('id' => 1));;    
    header("Content-Type: application/rss+xml");
    $this->load->view('rss_feed', $data);

}
function rss_feed()  
    {  
            $data['encoding']           = 'utf-8'; // the encoding
            $data['feed_name']          = 'MyWebsite.com'; // your website  
            $data['feed_url']           = 'http://www.MyWebsite.com/feed'; // the url to your feed  
            $data['page_description']   = 'What my site is about comes here'; // some description  
            $data['page_language']      = 'en-en'; // the language  
            $data['creator_email']      = 'mail@me.com'; // your email  
            $data['posts']              = $this->feed_model->getRecentPosts();  
            header("Content-Type: application/rss+xml"); // important!
            $this->load->view('rss', $data);

    }
视图:


版权

$entry->post\u body
未定义

这也是一件小事,但您有两个分号:
$data['posts']=$this->db->order_by(“id”,“asc”)->get_where('rss_feed',array('id'=>1))这正困扰着我。是的,但我不喜欢

尊重MVC,在CI_模型中使用“$this->db->order_by(“id”,“asc”)->get_where…”,例如:

您的CI_控制器:

function rss_feed($limit = NULL)  
{
    $data['encoding'] = 'utf-8';
    $data['feed_name'] = 'neginph.com';
    $data['feed_url'] = 'http://www.neginph.com';
    $data['page_description'] = 'Mono-calcium phosphate and calcium phosphate producer in the Persian month Dey';
    $data['page_language'] = 'en-en';
    $data['creator_email'] = 'Negin phosphate North';
    $data['posts'] = $this->db->order_by("id", "asc")->get_where('rss_feed', array('id' => 1));;    
    header("Content-Type: application/rss+xml");
    $this->load->view('rss_feed', $data);

}
function rss_feed()  
    {  
            $data['encoding']           = 'utf-8'; // the encoding
            $data['feed_name']          = 'MyWebsite.com'; // your website  
            $data['feed_url']           = 'http://www.MyWebsite.com/feed'; // the url to your feed  
            $data['page_description']   = 'What my site is about comes here'; // some description  
            $data['page_language']      = 'en-en'; // the language  
            $data['creator_email']      = 'mail@me.com'; // your email  
            $data['posts']              = $this->feed_model->getRecentPosts();  
            header("Content-Type: application/rss+xml"); // important!
            $this->load->view('rss', $data);

    }
在您的CI_模型中:

class Feed_Model extends CI_Model {

    // get all postings  
    function getRecentPosts()  
    {  
        $this->db->order_by('id', 'asc');
        $this->db->limit(10);
        return $this->db->get('posts');
    }

}
然后你喂:

<?php 
echo '<?xml version="1.0" encoding="utf-8"?>' . "\n";
?>


<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>
        <dc:rights>Copyright <?php echo gmdate("Y", time()); ?></dc:rights>  

        <admin:generatorAgent rdf:resource="http://www.codeigniter.com/" />

        <?php foreach($posts->result() as $entry): ?>  

            <item>  
                <title><?php echo xml_convert($entry->title); ?></title> 
                <link><?php echo site_url('blog/post/' . $entry->id) ?></link>
                <guid><?php echo site_url('blog/post/' . $entry->id) ?></guid>

                <description><![CDATA[<?php echo character_limiter($entry->text, 200); ?>]]></description>
                <pubDate><?php echo date ('r', $entry->date);?></pubDate>

            </item>  

        <?php endforeach; ?>

        </admin:generatoragent>

    </channel>

</rss>  

版权
标题);?>
文本,200);?>]]>

$entry->post_body
应该在哪里使用?似乎没有从数据库中选择它。