Welcome Guest, Not a member yet? Register   Sign In
Simple question about Helpers
#1

[eluser]russ_kern[/eluser]
In the Users Guide it says about Helpers:

"... Once loaded, it becomes globally available in your controller and views."

What about your models? Are they globally available there as well?

If I have Called the Date Helper in my Controller, but a model needs that functionality, do I need to recall it within the model? Or since I called it in the Controller is it automatically available?

Thanks in advance... Russ
#2

[eluser]InsiteFX[/eluser]
You will need to use the $this->helper->function

If it will not work then load it in your model.

InsiteFX
#3

[eluser]CI Coder[/eluser]
[quote author="InsiteFX" date="1301383966"]You will need to use the $this->helper->function

If it will not work then load it in your model.

InsiteFX[/quote]

Well... I don't know about that. Helpers are just collections of functions, not methods of classes, so you can't do
Code:
$this->helper->function

Basically
Code:
$this->load->helper(...)
does exactly what
Code:
require_once
does in PHP with the added ease of not having to specify the full path to the file as well as being able to add your own helper functions or to overwrite the ones that ship with CI under the same name.

If you load a helper in the constructor of your controller, all its member functions should be available in all the models that you use in all the controller methods. That is, only if you don't use some sort of hook or rig the system some other way to use the helper before the controller instantiates. In that case you're on your own.

My advice is to load anything you need when you need it. The Loader class keeps track of what it's loaded and it won't load it again. It basically makes everything a singleton.

Hope that helps.
#4

[eluser]russ_kern[/eluser]
Thanks for the replies... it seems that once you load it it is also available everywhere...

Also, I forgot that I can just autoload it in the autoload file, which is what I did since I use it so much.

Thanks for the replies.

R




Theme © iAndrew 2016 - Forum software by © MyBB