CodeIgniter Forums
Basic question - need some pointers on extending a library - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Basic question - need some pointers on extending a library (/showthread.php?tid=64945)



Basic question - need some pointers on extending a library - michaelh99 - 04-13-2016

Or a definitive "you can't do that".

I'm using the HMVC libraries for CI and have an "admin" module that I've been using for several years.  Within that module is an "authentication" library that I use all over the place.

I've got some app-specific code that's been pushed down into the module and I'd like to decouple the two.

To that end I've created an AppAuthentication class that my app loads which extends the module Authentication.  I've got appropriate functions overloaded in my version so that I can perform app-specific operations after login and logout.

The problem is that the module still wants to load the base version and so my overload never gets called.

How can I get the module to load my class without having app-specific code down in the module?

Would I need to pass an instance of my class down to the authentication module and mod it use use that?

Or am I asking for too much?

Sorry for the basic question but there are still swaths of PHP I'm not familiar with.


RE: Basic question - need some pointers on extending a library - michaelh99 - 04-13-2016

Looks like I might have figured out a method for this.

I put the module's class in the namespace 'admin' and left everything else in the module alone.
I require_once that class and extend admin\Authentication and name my class Authentication.

Since everything is just loading an "Authentication" class, they end up with my subclass