$this keyword in view in CodeIgniter |
I'm trying to understand how
Code: $this->load->view() 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 Code: $this 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,
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().
Code: $this->load =& load_class('Loader');
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)
|
Welcome Guest, Not a member yet? Register Sign In |