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

#1
I'm trying to understand how 

Code:
$this->load->view()
 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 

Code:
include('/path/to/view');
Shouldn't 

Code:
$this
 refer to the Loader class at that point? How is 

Code:
$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, 

Code:
$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
Reply

#2
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 )
Reply

#3
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)
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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