TranLinh TranLinh - 7 months ago 46
PHP Question

Where is Load method In CI_Controller

In system/core/Controller.php I see the following code:

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');
}


I tried many time to find load method, load_class() ...

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


Where are they?

Answer

The function load_class() is defined in system/core/common.php which is included in the last line of index.php like so

require_once BASEPATH.'core/CodeIgniter.php';

CodeIgniter.php "bootstraps" the whole framework.

So, by the time a controller constructor runs the function load_class() is defined and ready to go to work.

load_class() is creating an instance of the Loader class for the controller to use. Loader has many methods. The most common use is to load other framework libraries, models, helpers and views. For example

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