CodeIgniter Forums

Full Version: $this keyword in view in CodeIgniter
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm trying to understand how 

 works [font=Arial,][i]inside[/i] of a view file in CodeIgniter.[/font]
The core/Controller.php is calling core/Loader.php which then calls _ci_load() which in turn does an 


 refer to the Loader class at that point? How is 

 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 [font=Arial,][i]user[/i]. Please do not leave answers explaining how to [i]use[/i] $this->load().[/font]
When it is used inside a view file $this-> is pointing to the views controller.

$this-> is the controller that fired off the view.
The reason $this is still the controller is that view files are not classes. Instead they are simply included into the current scope - usually the controller. In other words $this->load->view('some_view') is a fancy, high-powered way to say include(path/to/views/some_view.php)