2016-04-28 28 views
1

在系统/核心/ Controller.php这样我看到下面的代码:哪里是Load方法在是CI_Controller

public function __construct() 
{ 
    self::$instance =& $this; 

    // Assign all the class objects that were instantiated by the 
    // bootstrap file (CodeIgniter.php) to local class variables 
    // so that CI can run as one big super object. 
    foreach (is_loaded() as $var => $class) 
    { 
     $this->$var =& load_class($class); 
    } 

    $this->load =& load_class('Loader', 'core'); 
    $this->load->initialize(); 
    log_message('info', 'Controller Class Initialized'); 
} 

我试了很多时间去寻找加载方法,load_class()...

 $this->load =& load_class('Loader', 'core'); 
     $this->load->initialize(); 

他们在哪里?

+0

转到'/系统/核心/ Loader.php'并运行'公共功能视图的搜索(','公共函数库(','公共函数模型('等。 – MonkeyZeus

+0

目前还不清楚我还找不到答案 – TranLinh

回答

1

load_class()system/core/common.php定义的函数,它被包括在index.php最后一行像这样

require_once BASEPATH.'core/CodeIgniter.php'; 

CodeIgniter.php“自举”整个框架。

所以,当一个控制器构造函数运行函数load_class()被定义并准备开始工作。

load_class()正在为控制器创建一个Loader类的实例。 Loader有很多方法。最常见的用途是加载其他框架库,模型,帮助程序和视图。 例如

$this->load->library('form_validation'); 
$this->load->model('your_favorite_model'); 
$this->load->helper('url'); 
$this->load->view('welcome_view'); 
+0

如何在不包含include,require文件或扩展类的情况下调用它? – TranLinh

+0

我不清楚“it”是什么,你想调用什么? – DFriend

+0

正如你在CI_Controller类中看到的那样,没有require文件或扩展类。我怎样才能在CI_Controller中使用'load_class()'? – TranLinh