CodeIgniter Forums
Traits & Interface - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6)
+--- Forum: CodeIgniter 2.x (https://forum.codeigniter.com/forumdisplay.php?fid=18)
+--- Thread: Traits & Interface (/showthread.php?tid=61679)



Traits & Interface - calcio - 05-05-2015

Hi everyone.

I need to know how to implement Traits & Interface on CI 2.x.
My doubt is, where I creat it? On Model, Controllers, Libraries? Where?

Everyone alredy use these features?


RE: Traits & Interface - orionstar - 05-05-2015

If it belongs to a library, I usually put them into the libraries folder and create a subfolder with the library's name (for example: I have a Notification library, then I create a folder in the libraries called Notification and put my own classes, interfaces etc. into that and I use require/include or an spl autoload function).
If it's anything else, then put it to application/third_party and put an spl_autoload to the front controller (main index.php).
If it is a complex stuff then create a PSR-4 compliant package and use composer's autoloader.


RE: Traits & Interface - calcio - 05-06-2015

Thanks @orinstar. I'll try it.
Before your answer I tried use a library.