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.
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.
load
is an attribute of the current object. The attribute itself holds an object that has a view()
method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With