CodeIgniter Forums
Objects in CI, are they ever used? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Choosing CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=8)
+--- Thread: Objects in CI, are they ever used? (/showthread.php?tid=65987)



Objects in CI, are they ever used? - allusers - 08-19-2016

Are they? In the controller file, I mean.
I dont see the new operator used much or other objects instantiated. New to CI.


RE: Objects in CI, are they ever used? - albertleao - 08-19-2016

You can write a model or library in instantiate it with the "new className();" method anywhere in CI.

You can see how CI loads packages here too :
http://www.codeigniter.com/user_guide/libraries/loader.html#application-packages


RE: Objects in CI, are they ever used? - dave friend - 08-23-2016

Yes, "objects" are used in CI. The loader class (/system/core/loader.php) does instantiation of any class it is asked to load.


RE: Objects in CI, are they ever used? - skunkbad - 08-23-2016

A simplified summary of the way CodeIgniter works is that there is a "super object", and the loader class adds new classes as properties of that super object. That's why when you're in a controller and you load a library, you then use it with $this->.

That is one of the fundamental reasons why CI is so easy to use, but also a reason that CI is heavily criticized. "Modern" PHP frameworks will have a totally different kind of autoloading and class usage. There is nothing stopping you from autoloading this way in CI, and depending on the classes you are using, you might have to. When I use a library of some classes that require autoloading, I'll usually use Symfony's PSR4 class autoloader.