Welcome Guest, Not a member yet? Register   Sign In
helpers and loading only what you really need
#1

[eluser]moonbeetle[/eluser]
I appologize in adavance if this has been asked before. I know of a post where someone partially answered my question but after searcing for nearly an hour I can't find the post again.

Is there any way to call a function from a helper without having to load the entire helper?
Suppose I have a helper called "sanitize_helper" with a bunch of format validation functions but I only need one specific function.

I once read a post about using a helper, declaring it as a class and defining all functions as public static methods. So I could do something like:
Code:
$startdate = Sanitize::checkDateFormat($this->input->post('startdate'));
But since this only works if I load the helper first with
Code:
$this->load->helper('sanitize');
I'm loading the entire helper code, right?
#2

[eluser]tonanbarbarian[/eluser]
Yeah if you want to use any function in a helper you have to load the helper which grabs all of its functions
I think this is what plugins are supposed to be for, but since CI doesnt come with any plugins by default it is a little unclear
Plugins are supposed to be single functions that you can load like helpers.
From what I can see they are exactly like helpers in every way (maybe i am wrong)
But what this means you might be able to do is take the helper that you want, strip the code that you need out of it and put it into a plugin and then load the plugin just when you need it

could be wrong though
(is there anyone who has actually used the plugin feature in CI and if so what for - maybe this question should be another post)
#3

[eluser]sikkle[/eluser]
in fact, plugins are suppose to be only one method, a helper file is usually more than one method.

So when i want to do micro-optimitization, yes i build a plugins with unique function in it.

good luck !




Theme © iAndrew 2016 - Forum software by © MyBB