views:

67

answers:

1

I’m fairly new to CodeIgniter and have a question. I’m a bit confused about Classes, Libraries and Objects.

Does CodeIgniter replace the normal PHP way of usings objects i.e. $var = new car(); with libraries i.e. $this->load->library('some_library'); $this->some_library->some_function(); ?

If both are valid, is there a difference? If so, what are the differences and when do I use one over the other? Which is more common/proper?

I am asking because I created a class, but I'm not certain what is the correct manner in which to instantiate it.

Thanks in advance

+3  A: 

I am not familiar with CodeIgnitier. But familiar with other PHP frameworks. Most of frameworks use this way for performance improvements, registering things, executing certain events, and making things simpler for developer...

For example if you want to create class "car" with is somewhere in library directory you would have to include the file first before you can create object of that class (miltiple lines of code, more room for error). The framework will create the class and includes related files in 1 line of code (easier and safer).

Framework way also works as a factory. Instead of recreating an object, it will create object only once and every time you call the method again it will return the reference to existing object.

More things are happening behind the scenes when you use framework. Things are getting registered, etc...

Alex