views:

587

answers:

2

I would like to check if my assumption about codeigniter is right ?

We would normally extend a class when we are trying to include more functionality to the core, such as MY_Controller extends Controller, MY_Model extends Model etc...

But for example, if we are in the checkout library retrieving some checkout info(eg, product_id), we can just $this->load->library('product_lib',array('product_id'=>$product_id)) and we can easily $this->product_lib->product_name etc... from the checkout library right?

The $this->load thing is kind of equivalent to "hard code" checkout library to extend product_lib(class checkout_lib extends product_lib) to be able to use whatever methods/variables there is in the product_lib.

Please enlighten me.

A: 

In CodeIgniter $this->load is like having a resource manager (e.g. resourceManager->load("path/to/file")) and it takes care of loading the library, and passing any arguments you specify and such, easily allowing you to quickly get to using it.

So if you have a variable named product_name in your product_lib then yes calling $this->product_lib->product_name will be accessing that variable.

Really it just places the library into an array with the library name as the key and the instance of the library as the value so calling $this->product_lib is really calling something similar to $loadedLibraries['product_lib'] and returning the instance.

I hope that answers what you are asking, I'm quite tired and could have miss understood you question.

Cory
+1  A: 

I think you misunderstood the OO paradigm and the way CI work.

$this->load is same with instantiate an object of the library/model, or load the helper file. CI have some sort of management to see if the helper/library/model already uploaded or not.

In other hand, the extends is used when defining a class, to tell PHP that the class will be inherit the parent class properties and method. A class is a blue print of object it will produce.

Maybe you can start by understanding the OO concept first. You can read this as a start, and see the reference used there.

Donny Kurnia