CodeIgniter Forums
Autoloading in CI 2.0 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: Autoloading in CI 2.0 (/showthread.php?tid=29802)



Autoloading in CI 2.0 - El Forum - 04-21-2010

[eluser]Dan Horrigan[/eluser]
If you are like me, you would like class autoloading supported in CI 2.0. I have a fork of CI 2.0 and have added this functionality. I have added this functionality, and it works great. It adds nearly zero over head. It only autoloads libraries, models and helpers...if you use static methods for helpers :-). It uses the CI_Loader functions, so all module paths are respected.. Here is how to use it:

Example for loading a library:
Code:
$auth = new Auth();
Or you can use static methods:
Code:
Auth::logged_in();
You get the idea.

You can also use it for Models:
Code:
$user = new User_model();
$user->get($user_id);

You models can still use $this->db.

I particularly like it for helpers (i know EllisLab says they should be procedural, but I like static methods...Issue #29):
Code:
Form::open('email/send');

If you like the idea encourage them to add it in. Issue #33

Here are my changesets (forgot to remove debug code the first time around :-P):
https://bitbucket.org/dhorrigan/codeigniter/changeset/02aec4b35443
https://bitbucket.org/dhorrigan/codeigniter/changeset/97e9ac090a14

Dan