Autoloading library methods? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Autoloading library methods? (/showthread.php?tid=38131) Pages:
1
2
|
Autoloading library methods? - El Forum - 01-31-2011 [eluser]Wayne Smallman[/eluser] Hi guys! I've found the options for autoloading a library, but I was wondering if there's a way of autoloading a method, or several methods, within a library? Having built the core of my application, I can now see that there's a need to have a global library for managing several things (such as navigation, message notifications and the like), which I can't really do without re-building hundreds of views. Any ideas? Autoloading library methods? - El Forum - 01-31-2011 [eluser]johnpeace[/eluser] Call the method(s) from the library's constructor? Autoloading library methods? - El Forum - 01-31-2011 [eluser]Wayne Smallman[/eluser] [quote author="johnpeace" date="1296499554"]Call the method(s) from the library's constructor?[/quote]Hi John! But I'd have to add that call into every single controller throughout the whole of the application, surely? Autoloading library methods? - El Forum - 01-31-2011 [eluser]InsiteFX[/eluser] That is what a MY_Controller is for! InsiteFX Autoloading library methods? - El Forum - 01-31-2011 [eluser]Wayne Smallman[/eluser] [quote author="InsiteFX" date="1296501500"]That is what a MY_Controller is for![/quote]That's interesting. I can do a search and replace through my IDE to swap the core controller name for the new one. Thanks, that should work fine! Autoloading library methods? - El Forum - 01-31-2011 [eluser]InsiteFX[/eluser] If you have any trouble let me know. This is also in the CodeIgniter User Guide. InsiteFX Autoloading library methods? - El Forum - 01-31-2011 [eluser]Wayne Smallman[/eluser] [quote author="InsiteFX" date="1296503942"]If you have any trouble let me know. This is also in the CodeIgniter User Guide.[/quote]I wouldn't have noticed as I've not needed anything like this before. Incidentally, between now and my previous reply, and added MY_Controller and updated the whole application in the process. Thanks again. Autoloading library methods? - El Forum - 01-31-2011 [eluser]Phil Sturgeon[/eluser] Wayne: Reading this article should help you out: http://philsturgeon.co.uk/news/2010/02/CodeIgniter-Base-Classes-Keeping-it-DRY Autoloading library methods? - El Forum - 01-31-2011 [eluser]Wayne Smallman[/eluser] [quote author="Phil Sturgeon" date="1296504690"]Wayne: Reading this article should help you out: http://philsturgeon.co.uk/news/2010/02/CodeIgniter-Base-Classes-Keeping-it-DRY[/quote]Hi Phil, thanks for the link. Having gone ahead with this, I've now realized this technique is still not what I want — I want to be able to autoload a controller and then invoke a series of functions, so I don't have to add them into every controller. From what I can see here, there's still no way of doing that; I've still got to add the required code into every single controller. Or am I missing something? Autoloading library methods? - El Forum - 01-31-2011 [eluser]Phil Sturgeon[/eluser] If you give me some examples perhaps I could give you a more accurate answer. This will not make something run on EVERY controller, only those that extend a type of base controller. By giving your controllers types you specify what sort of functions should be run by default. Admin_Controller extends MY_Controller Public_Controller extends MY_Controller AJAX_Controller extends MY_Controller WHYWSIWYG_Controller extends Admin_Controller You can create all sorts of combination's for the various types of functionality parts of your site needs. |