|
get_config()获取config.php里的所有配置信息,config_item()获取某一条配置信息,放在common.php里是为了更方便,config_item()依赖于get_config()
CI_Config类还能获取到config目录下的xx.php,在构造函数里也使用到了get_config()函数 | |
|
写得不错,不过看着累,看源码更轻松些,毕竟CI的源码比较简单,建议先自己看源码后再来看教程
| |
|
有个问题要请教下大神。{:soso_e100:} 我用的是最新版本的ci function _fetch_uri_string() { if (strtoupper($this->config->item('uri_protocol')) == 'AUTO') { // Is the request coming from the command line? if (php_sapi_name() == 'cli' or defined('STDIN')) { $this->_set_uri_string($this->_parse_cli_args()); return; } // Let's try the REQUEST_URI first, this will work in most situations if ($uri = $this->_detect_uri()) { $this->_set_uri_string($uri); return; } // Is there a PATH_INFO variable? // Note: some servers seem to have trouble with getenv() so we'll test it two ways $path = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO'); if (trim($path, '/') != '' && $path != "/".SELF) { $this->_set_uri_string($path); return; } // No PATH_INFO?... What about QUERY_STRING? $path = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING'); if (trim($path, '/') != '') { $this->_set_uri_string($path); return; } // As a last ditch effort lets try using the $_GET array if (is_array($_GET) && count($_GET) == 1 && trim(key($_GET), '/') != '') { $this->_set_uri_string(key($_GET)); return; } // We've exhausted all our options... $this->uri_string = ''; return; } $uri = strtoupper($this->config->item('uri_protocol')); if ($uri == 'REQUEST_URI') { $this->_set_uri_string($this->_detect_uri()); return; } elseif ($uri == 'CLI') { $this->_set_uri_string($this->_parse_cli_args()); return; } $path = (isset($_SERVER[$uri])) ? $_SERVER[$uri] : @getenv($uri); $this->_set_uri_string($path); } 看到pathinfo的优先级在第二位了,第一优先是取REQUEST_URI,SCRIPT_NAME, 没有优选pathinfo,于是我有这个想法,在nginx的配置是不是可以不配置pathinfo,结果ci不能正常运行 最后发现,没有配置pathinfo $_SERVER: [SCRIPT_NAME] => /ci/index.php/comments/add_comments[REQUEST_URI] => /ci/index.php/comments/add_comments 配置pathinfo: [SCRIPT_NAME] => /ci/index.php [REQUEST_URI] => /ci/index.php/comments/add_comments 而通过 CI源代码( URI._detect_uri() )发现 $uri = substr($uri, strlen($_SERVER['SCRIPT_NAME'])); 解析出uri的关键就是根据这两个参数,究竟pathinfo和SCRIPT_NAME有什么关系,这是个让我百思不得其解的问题,网上没查到,so问问大神。。。 我的环境 ubuntu + php5.4.19+nginx/1.5.1 | |