收藏本站 Archiver
    请 后使用快捷导航
    没有账号?入住 CI 中国社区
    楼主: Hex

    [中级] CodeIgniter 源代码解析

    [复制链接]
    31
    楼主| 发表于 2013年5月19日 11:33:34 | 只看该作者
    优雅de凋零 发表于 2013年5月19日 00:06
    终于找到了啊.................
    URI类中的 _fetch_uri_string()方法
    里面有这样一句 if($uri = $this->_det ...

    这要具体问题具体分析了,正常情况都不会为 false 的。
    32
    发表于 2013年7月4日 18:49:48 | 只看该作者
    好帖,收藏了
    33
    发表于 2013年8月11日 00:20:14 | 只看该作者
    我顶 对不起来这一遭
    34
    发表于 2013年9月7日 22:30:24 | 只看该作者
    get_config()获取config.php里的所有配置信息,config_item()获取某一条配置信息,放在common.php里是为了更方便,config_item()依赖于get_config()

    CI_Config类还能获取到config目录下的xx.php,在构造函数里也使用到了get_config()函数
    35
    发表于 2013年9月7日 22:48:21 | 只看该作者
    写得不错,不过看着累,看源码更轻松些,毕竟CI的源码比较简单,建议先自己看源码后再来看教程
    36
    发表于 2013年9月8日 11:27:46 | 只看该作者
    Hex 发表于 2009年8月22日 01:33
    (接楼上)

    Router类与HTTP请求解析

    有个问题要请教下大神。{: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
    37
    发表于 2013年12月14日 16:59:42 | 只看该作者
    mark
    38
    发表于 2013年12月17日 15:53:52 | 只看该作者
    mark。。。
    39
    楼主| 发表于 2013年12月17日 20:00:39 | 只看该作者
    Lin17 发表于 2013年9月8日 11:27
    有个问题要请教下大神。
    我用的是最新版本的ci
    function _fetch_uri_string()

    其实很简单,支持 PATH_INFO 的话就不会把整个 URI 都当作文件名。
    这里只是个环境变量而已,没有什么特殊的。

    40
    发表于 2014年1月6日 10:59:22 | 只看该作者
    收藏下
    下一页 »
    1 2 3 45 下一页
    返回列表
    您需要登录后才可以回帖 登录 | 入住 CI 中国社区

    本版积分规则

    AltStyle によって変換されたページ (->オリジナル) /