|
楼主 |
发表于 2012-3-29 17:47:58
|
显示全部楼层
CodeIgniter2.1.0源码阅读(5)URL.php url处理类
本帖最后由 actionbi 于 2012-3-30 02:33 编辑
在CodeIgniter.php中,第165行加载了URL类。目的是为了进行url的处理,类CI_URL也是个全局加载的类库,可以直接使用。
参数介绍:
$keyval = array(); //缓存的uri片段
var $uri_string;
/*
* 获取到的当前的URI的字符串
* 当你的URl为localhost/CodeIgniter/index.php?/welcome/index/var/4时
* $uri_string = welcome/index/var/4
*/
var $segments = array(); //URI片段数组 数组键值从0开始
var $rsegments = array(); //重建索引的片段数组 数组键值从1开始
附录:
url类中ci判断php的运行环境
CodeIgniter源码阅读URI.php中_fetch_uri_string()函数的解析
PHP复制代码
<?php
class CI_URI {
var $keyval = array();
var $uri_string;
/*
* 获取到的当前的URI的字符串
* 当你的URl为localhost/CodeIgniter/index.php?/welcome/index/var/4时
* $uri_string = welcome/index/var/4
*/
var $segments = array(); //URI片段数组 数组键值从0开始
var $rsegments = array(); //重建索引的片段数组 数组键值从1开始
function __construct (){
$this->config =& load_class ('Config', 'core');
log_message ('debug', "URI Class Initialized");
//加载了core/Config.php 也就是Config类,需要获取config文件中的设置
}
function _fetch_uri_string (){}//获取uri_sting 详细见附录
function _set_uri_string ($str){
//过滤url中的不可见的字符
$str = remove_invisible_characters ($str, FALSE);
// If the URI contains only a slash we'll kill it
$this->uri_string = ($str == '/') ? '' : $str;
}
private function _detect_uri (){
//检测uri,经过此函数检测的uri将传送到_set_uri_string($str)
}
private function _parse_cli_args (){
$args = array_slice($_SERVER['argv'], 1);
return $args ? '/' . implode('/', $args) : '';
}
function _filter_uri ($str){
//过滤url的参数
//过滤规则为 |^[a-z 0-9~%\.\:_\-]+$|i 当uri的参数不符合条件时会报错
$bad = array('$', '(', ')', '%28', '%29');
$good = array('$', '(', ')', '(', ')');
}
function _remove_url_suffix (){
//取出uri的后缀
}
function _explode_segments (){
//将$this->uri_string 分割到数组中
//期间分割字符串要使用到_filter_uri($str)
}
function _reindex_segments (){
//为segements 重建索引
}
function segment ($n, $no_result = FALSE){
//获取uri的一个 片段
return ( ! isset($this->segments[$n])) ? $no_result : $this->segments[$n];
}
function rsegment ($n, $no_result = FALSE){
//获取uri的一个片段
return ( ! isset($this->rsegments[$n])) ? $no_result : $this->rsegments[$n];
}
function uri_to_assoc ($n = 3, $default = array()){
return $this->_uri_to_assoc ($n, $default, 'segment');
}
function ruri_to_assoc ($n = 3, $default = array()){
return $this->_uri_to_assoc ($n, $default, 'rsegment');
}
function _uri_to_assoc ($n = 3, $default = array(), $which = 'segment'){
//uri片段转换成一个关联数组,据说是做cache,但是有点苦,函数懂了,但是用法不知
}
function assoc_to_uri ($array){
//将uri片段的关联数组转换成uri
}
function slash_segment ($n, $where = 'trailing'){
return $this->_slash_segment ($n, $where, 'segment');
}
function slash_rsegment ($n, $where = 'trailing'){
return $this->_slash_segment ($n, $where, 'rsegment');
}
function _slash_segment ($n, $where = 'trailing', $which = 'segment'){
}
function segment_array (){
return $this->segments;
//返回uri片段数组
}
function rsegment_array (){
return $this->rsegments;
//返回中间索引后uri片段数组
}
function total_segments (){
return count($this->segments);
//返回uri片段数
}
function total_rsegments (){
return count($this->rsegments);
}
function uri_string (){
return $this->uri_string;
//获取当前的uri字符串
}
function ruri_string (){
return '/'.implode('/', $this->rsegment_array());
}
}
?>
复制代码 |
|