当前位置:编程学习 > php >>

Codeigniter Rss,网站地图,路由配置

_ _,今天在成果不错,完成了网站的三个功能,RSS订阅,自动写网站地图,与路由的配置,好了,现在一 一记录下来.
 
 
 
 
一、路由配置
 
在未设定路由时,路径是这样的
 
 
[php] 
http://www.xiuxiandou.com/content/it/13533/硅谷传奇投资人讲述初创企业家易犯的4大错误   
                   
content =>controller,it=>method,13533=>id,硅谷传奇投资人讲述初创企业家易犯的4大错误=>title  
 
http://www.xiuxiandou.com/content/it/13533/硅谷传奇投资人讲述初创企业家易犯的4大错误
                 
content =>controller,it=>method,13533=>id,硅谷传奇投资人讲述初创企业家易犯的4大错误=>title
设置路由后,访问路径为:
 
 
 
[php] 
http://www.xiuxiandou.com/content-it-13533-硅谷传奇投资人讲述初创企业家易犯的4大错误  
 
http://www.xiuxiandou.com/content-it-13533-硅谷传奇投资人讲述初创企业家易犯的4大错误
其它的类似,路径配置为
 
 
 
[php] 
/*sitemap使用*/  
$route['content-(:any)-(:num)'] = "content/$1/$2";  
/*前台页面显示路由*/  
$route['content-(:any)-(:num)-(:any)'] = "content/$1/$2/$3";  
                  
/*RSS订阅路由*/  
$route['feed-rss-(:any)'] = "feed/rss/$1";  
/*博客路由*/  
$route['blog-(:num)-(:any)'] = "blog/blogview/$1/$2";  
$route['blog-blogtypes-(:any)']="blog/blogtypes/$1";  
                  
/**留言**/  
$route['me'] = "indexs/me";  
/**模板**/  
$route["template"]="indexs/template";  
/**今日更新**/  
$route["indexs-(:any)"]="indexs/$1";  
 
/*sitemap使用*/
$route['content-(:any)-(:num)'] = "content/$1/$2";
/*前台页面显示路由*/
$route['content-(:any)-(:num)-(:any)'] = "content/$1/$2/$3";
                
/*RSS订阅路由*/
$route['feed-rss-(:any)'] = "feed/rss/$1";
/*博客路由*/
$route['blog-(:num)-(:any)'] = "blog/blogview/$1/$2";
$route['blog-blogtypes-(:any)']="blog/blogtypes/$1";
                
/**留言**/
$route['me'] = "indexs/me";
/**模板**/
$route["template"]="indexs/template";
/**今日更新**/
$route["indexs-(:any)"]="indexs/$1";
 
 
二、RSS
 
在libraries目录下创建Rss.php文件,主要负责生成RSS格式的数据内容
 
 
[php]  
<?php if(!defined('BASEPATH')) exit('No direct script access allowed');  
/** 
 * Rss 
 */  
class Rss{  
                      
    public function write_rss($in_datas){  
            $CI=& get_instance();  
            $CI->load->helper('xml');  
            $CI->load->helper('text');  
                  
            $xml_str="<?xml version='1.0' encoding='UTF-8'?>"  
                    ."<rss version='2.0' xmlns:content='http://purl.org/rss/1.0/modules/content/'  xmlns:wfw='http://wellformedweb.org/CommentAPI/' xmlns:dc='http://purl.org/dc/elements/1.1/' xmlns:atom='http://www.w3.org/2005/Atom' xmlns:sy='http://purl.org/rss/1.0/modules/syndication/'    xmlns:slash='http://purl.org/rss/1.0/modules/slash/'    >";  
            if(!emptyempty($in_datas)){  
                    $xml_str.="<channel>"  
                                ."<title>".$in_datas["feed_name"]."</title>"  
                                ."<atom:link href='".$in_datas["feed_url"]."' rel='self' type='application/rss+xml' />"  
                                ."<link>".$in_datas["feed_url"]."</link>"  
                                ."<description>".$in_datas["page_description"]."</description>"  
                                ."<language>zh-cn</language> "  
                                ."<sy:updateFrequency>1</sy:updateFrequency>"  
                                ."<sy:updatePeriod>hourly</sy:updatePeriod> "  
                                ."<dc:rights>Copyright (C) Xiuxiandou.com. All rights reserved.</dc:rights>"  
                                ."<generator>http://www.xiuxiandou.com</generator>";  
                                if(!emptyempty($in_datas["xml_datas"])){  
                                    foreach($in_datas["xml_datas"] as $k => $v){  
                                        foreach($v as $xml){  
                                            $xml_str.=" <item>"  
                       
补充:Web开发 , php ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,