Welcome Guest, Not a member yet? Register   Sign In
Autoloading library methods?
#1

[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?
#2

[eluser]johnpeace[/eluser]
Call the method(s) from the library's constructor?
#3

[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?
#4

[eluser]InsiteFX[/eluser]
That is what a MY_Controller is for!

InsiteFX
#5

[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!
#6

[eluser]InsiteFX[/eluser]
If you have any trouble let me know.

This is also in the CodeIgniter User Guide.

InsiteFX
#7

[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.
#8

[eluser]Phil Sturgeon[/eluser]
Wayne: Reading this article should help you out:

http://philsturgeon.co.uk/news/2010/02/C...ing-it-DRY
#9

[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/C...ing-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?
#10

[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.




Theme © iAndrew 2016 - Forum software by © MyBB