Welcome Guest, Not a member yet? Register   Sign In
Common functions - best practices
#1

[eluser]m40[/eluser]
I need to have a few functions available to multiple controllers and I was wondering where functions like these should reside.

To be more specific, I have a function called _encrypt_password() and two controllers that make use of it. I have placed the function in MY_Controller, but I was wondering if that would be considered a good practice.
#2

[eluser]bretticus[/eluser]
See Helpers in manual.
#3

[eluser]brianw1975[/eluser]
another option would be to put it in a helper then you could load that helper only when it is needed (twice) instead of having that function registered on every page where you use MY_Controller
#4

[eluser]m40[/eluser]
I thought about this, but my understanding is that helpers should be reusable pieces/modules and the function in question is very application specific and I don't know...
#5

[eluser]bretticus[/eluser]
[quote author="m40" date="1251837183"]I thought about this, but my understanding is that helpers should be reusable pieces/modules and the function in question is very application specific and I don't know...[/quote]

If your method is likely to be used by every controller, than putting it in MY_controller seems appropriate.
#6

[eluser]brianw1975[/eluser]
[quote author="bretticus" date="1251838013"][quote author="m40" date="1251837183"]I thought about this, but my understanding is that helpers should be reusable pieces/modules and the function in question is very application specific and I don't know...[/quote]

If your method is likely to be used by every controller, than putting it in MY_controller seems appropriate.[/quote]

I concur, and, just as you (m40) said, the _encrypt_password() is used in only 2 controllers, not site wide. Given that, loading a helper with that function in just those two controllers is more resource frugal than putting it in MY_Controller - which, as I said, will define and allocate memory for that function everytime the MY_Controller is used. Not that big of a deal when you are talking one visitor. but scale that up to 500 or 1000 and it will eat up more memory, and then extend that awareness from just one function to 5, 10, 15 or 20 functions over the entire site... and well, you'll see why other frameworks become very bloated and have overly large foot prints, kinda like this response.
#7

[eluser]m40[/eluser]
I see your point! Thanks!




Theme © iAndrew 2016 - Forum software by © MyBB