• 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Objects in CI, are they ever used?

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

#2
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/li...n-packages
Codeigniter is simply one of the tools you need to learn to be a successful developer. Always add more tools to your coding arsenal!
Reply

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

#4
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.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2017 MyBB Group.