Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

explaining $this->load->view()

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.

like image 638
never_had_a_name Avatar asked Dec 29 '22 20:12

never_had_a_name


2 Answers

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.

like image 179
meagar Avatar answered Dec 31 '22 08:12

meagar


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

like image 45
Ignacio Vazquez-Abrams Avatar answered Dec 31 '22 08:12

Ignacio Vazquez-Abrams