I’m trying to understand how $this->load->view() works inside of a view file in CodeIgniter.
The core/Controller.php is calling core/Loader.php which then calls _ci_load() which in turn does an include('/path/to/view');
Shouldn’t $this refer to the Loader class at that point? How is $this referring to the controller?
By my understanding, you should have to call $this->view() inside of a view file. Not $this->load->view() because the load() function is not accessible inside of the Loader. It’s a class variable of the Controller base class. i.e, $this->load =& load_class('Loader');
Please note: I’m trying to understand the CodeIgniter internals. I know perfectly well how to embed view files in other view files as a CodeIgniter user. Please do not leave answers explaining how to use $this->load().
Last time I checked,
$thiswas of classCI_Loader, tryvar_dump($this);inside a view.Check out:
https://github.com/EllisLab/CodeIgniter/blob/develop/system/core/Controller.php
is_loaded();returns an array with the already loaded classnames and their aliases from the main container.$this->loadis then an instance ofCI_Loaderinside the controller.Check:
https://github.com/EllisLab/CodeIgniter/blob/develop/system/core/Loader.php
Line 778