我正在尝试将本教程与我发布的新闻报道相匹配,但有些地方不起作用,我不太确定在哪里。
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
答案 0 :(得分:3)
某处某些地方不起作用,我不确定在哪里。
您链接到的错误消息确切地指出了错误所在的位置:
语法错误,第1行/home/xtremer/public_html/application/views/rss.php中的意外T_STRING
该文件的第1行是:
<!--?php echo '<?xml version="1.0" encoding="' . $encoding . '"?-->' . "\n"; ?>
这是无效的语法。从您引用的教程中,您想要的是:
<?php echo '<?xml version="1.0" encoding="' . $encoding . '"?>' . "\n"; ?>
您的视图中有多个PHP标记实例错误地写在<!--?php
中,因此您也必须纠正这些错误。