![]() |
Extending libraries - 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: Extending libraries (/showthread.php?tid=38328) |
Extending libraries - El Forum - 02-04-2011 [eluser]Basketcasesoftware[/eluser] Ok. The User Guide is very good about telling you how to extend, or even replace, the native libraries. Unfortunately it's completely mute on the subject of extending you own libraries. Is this possible using the CodeIgniter framework? I have a need to create a user extended base class. The base class is doing some housekeeping that the user don't need to mess with. I can think of a mechanism to do this much like how CodeIgniter itself works but that's possibly getting a little extreme. No, I don't want to use hooks because of the risk of a user accidentally overriding a core CodeIgniter function. Extending libraries - El Forum - 02-05-2011 [eluser]Basketcasesoftware[/eluser] Starting to analyze the CodeIgniter Loader class. Undocumented feature: Code: $libraries=array('email', 'ftp', 'html'); This works because the Loader class library function tests for, and will iterate through, an array of library names, applying the second and third arguments to each library loaded. And so far the answer to my above question is 'no'. I see a possible bug due to the discovered feature in the case it's used with a third argument. What if the first argument is an array and the third is not? I know how to patch it if it is a bug. I'll investigate it more. Extending libraries - El Forum - 02-05-2011 [eluser]Basketcasesoftware[/eluser] It is a... feature? The following code will work. Sort of. Code: $this->load->library(array('calendar', 'cart', 'email'), , 'mail'); A possible use for this is to take advantage of the initializers of the discarded classes because that's what the loader will do in the above example. It will create an instance and initialize each of the classes in order, discarding that previous class for the newer one. Could be used for the side effects. Here is my suggested rewrite of the Loader library function: Code: * This function lets users load and instantiate classes. Ouch! This took hours to re-write. And I think I already know how to answer the question I proposed at the beginning of this thread. Hooks. Extending libraries - El Forum - 02-05-2011 [eluser]Basketcasesoftware[/eluser] Oops. Wrong loader. I think mine is better though. ![]() But I was right about the array input on the first argument not being documented. Plus there is unreachable code. I'm going to use this thread to mark a hook I'm about to write to change the loader function into a more useful form than currently defined. It looks like the current version is a last minute bug fix! |