CodeIgniter 中发起的Controller在哪里

问题描述 投票:0回答:1

我想知道控制器在哪里启动(我的意思是文件包含在哪里,然后加载它的类并调用它的方法)。我想知道,因为我想对核心进行较小的修改。

我真正需要的是模拟调用新的控制器。我不需要像 HMVC 这样的技术,但我正在研究更简单的东西,但我确实需要模拟调用控制器,以便稍后与请求的控制器进行交互。

我已经扩展了核心的Loader类,以允许通过加载器类调用新的控制器,但我找不到控制器在哪里启动。

php class codeigniter controller
1个回答
1
投票

它位于

system/core/CodeIgniter.php
,从第 317 行到第 360 行(CodeIgniter 2.1.0)。

/*
 * ------------------------------------------------------
 *  Call the requested method
 * ------------------------------------------------------
 */
    // Is there a "remap" function? If so, we call it instead
    if (method_exists($CI, '_remap'))
    {
        $CI->_remap($method, array_slice($URI->rsegments, 2));
    }
    else
    {
        // is_callable() returns TRUE on some versions of PHP 5 for private and protected
        // methods, so we'll use this workaround for consistent behavior
        if ( ! in_array(strtolower($method), array_map('strtolower', get_class_methods($CI))))
        {
            // Check and see if we are using a 404 override and use it.
            if ( ! empty($RTR->routes['404_override']))
            {
                $x = explode('/', $RTR->routes['404_override']);
                $class = $x[0];
                $method = (isset($x[1]) ? $x[1] : 'index');
                if ( ! class_exists($class))
                {
                    if ( ! file_exists(APPPATH.'controllers/'.$class.'.php'))
                    {
                        show_404("{$class}/{$method}");
                    }

                    include_once(APPPATH.'controllers/'.$class.'.php');
                    unset($CI);
                    $CI = new $class();
                }
            }
            else
            {
                show_404("{$class}/{$method}");
            }
        }

        // Call the requested method.
        // Any URI segments present (besides the class/function) will be passed to the method for convenience
        call_user_func_array(array(&$CI, $method), array_slice($URI->rsegments, 2));
    }

但是,你想要做的事情仍然没有任何意义。

© www.soinside.com 2019 - 2024. All rights reserved.