views:

71

answers:

3

In a controller you can use this method to load a view, but I want to know what happens behind the scenes here.

I'm new to PHP and frameworks, but I’ve learned the basics of OOP.

When $this->view() is called then the method in the current class or the parent class is used.

But what does $this->load->view() mean? What is the intermediate load? is it a function or is it a property?

Where is it located? How could it contain view()?

Grateful for explanation.

A: 

I would read the CodeIgniter Wiki Page regarding the View Object for more information.

Josh K
+3  A: 

The code in question is accessing a member variable named load, which has a method named view.

CodeIgniter, by its own convention, provides its models and libraries as member variables within the CI "super object", which is an instance of your controller. You can think of all models and plugins as singletons, whose single instance is assigned as a member of the singleton instance of your controller which CI automatically creates.

The load member in this particular is an instance of CI_Loader, which is responsible for loading additional models, views and libraries. It, in turn, assigns them to their own member variables within your controller's instance.

meagar
where can i find the line where the instantiating of CI_Loader to $load occur? for learning purpose. i have searched for $load (cause i wanted to find the property within the class holding it, but couldnt find a match).
never_had_a_name
In the _ci_initialize() method of the Controller class in system/libararies/Controller.php
Stephen Curran
+2  A: 

load is an attribute of the current object. The attribute itself holds an object that has a view() method.

Ignacio Vazquez-Abrams