我正试图将本教程与我为它发布的新闻故事相匹配,但在某个地方有些东西不工作,我不太确定在哪里。
http://net.tutsplus.com/tutorials/php/building-an-rss-2-0-feed-with-codeigniter/我已经自动加载了文本和xml帮助程序。
网页网址:http://www.kansasoutlawwrestling.com/news-feed
模型:
<?php
class Newsfeedmodel extends CI_Model {
function __construct()
{
// Call the Model constructor
parent::__construct();
}
// get all postings
function getPosts($limit = NULL)
{
$this->db->select('site_news_articles.article_title, site_news_articles.permalink, site_news_articles.date_published');
$this->db->from('site_news_articles');
$this->db->where('site_news_articles.is_approved', 'Yes');
$this->db->where('site_news_articles.status_id', 1);
$this->db->order_by('site_news_articles.date_published', 'desc');
$this->db->limit($limit);
$query = $this->db->get();
return $query->result_array();
}
}
?>
视图:
<!--?php echo '<?xml version="1.0" encoding="' . $encoding . '"?-->' . "'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>
<link><!--?php echo $feed_url; ?-->
<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 $post): ?>
<item>
<link><!--?php echo site_url('blog/posting/' . $post--->id) ?>
<guid><!--?php echo site_url('blog/posting/' . $post--->id) ?></guid>
<description><!--[CDATA[ <?php echo character_limiter($post--->text, 200); ?> ]]></description>
<pubdate><!--?php echo $post--->date; ?></pubdate>
</item>
<!--?php endforeach; ?-->
</admin:generatoragent></channel>
</rss>
控制器:
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Newsfeed extends CI_Controller
{
function Feed()
{
parent::__construct();
$this->load->model('newsfeedmodel', 'posts');
}
function index()
{
/**********************************************************Your Coding Logic Here, Start*/
$data['feed_name'] = 'Kansas Outlaw Wrestling, LLC.'; // your website
$data['encoding'] = 'utf-8'; // the encoding
$data['feed_url'] = 'http://www.kansasoutlawwrestling.com/newsfeed'; // the url to your feed
$data['page_description'] = 'True Outlaws of the Midwest'; // some description
$data['page_language'] = 'en-en'; // the language
$data['creator_email'] = 'kowmanagement@kansasoutlawwrestling.com'; // your email
$data['posts'] = $this->posts->getPosts(10);
$this->output->set_header("Content-Type: application/rss+xml"); // important!
$this->load->view('rss', $data);
/***********************************************************Your Coding Logic Here, End*/
}
}
/* End of file newsfeed.php */
/* Location: ./application/controllers/newsfeed.php */
编辑:使用上面的代码,我得到这个错误:
Parse error: syntax error, unexpected T_STRING in /home/xtremer/public_html/application/views/rss.php on line 1
哪里有东西不工作,我不太确定在哪里。
您链接到的错误信息准确地说明了错误所在的位置:
语法错误,在/home/xtremer/public_html/application/views/rss.php第1行出现意外T_STRING
该文件的第1行是这样的:
<!--?php echo '<?xml version="1.0" encoding="' . $encoding . '"?-->' . "'n"; ?>
这是无效的语法。从您引用的教程中,您需要的是:
<?php echo '<?xml version="1.0" encoding="' . $encoding . '"?>' . "'n"; ?>
看起来你有多个PHP标签的实例不正确地写在你的视图,如<!--?php
,所以你必须纠正这些