• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
$this keyword in view in CodeIgniter

I'm trying to understand how 

 works [i]inside[/i] 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 


 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 [i]user[/i]. Please do not leave answers explaining how to [i]use[/i] $this->load().
No SEO spam - see forum guidelines

When it is used inside a view file $this-> is pointing to the views controller.

$this-> is the controller that fired off the view.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )

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)

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.