CodeIgniter Forums

Full Version: I have my own Function file. How can i use that?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]web_developer[/eluser]
Hello,

I have my own function file, I would like to use in Model, View and Controller (anywhere)
How can I use that functions? (I have put that function file in library directory)

But now how can I access my functions in Model, Controller and in View?

El Forum

[eluser]saidai jagan[/eluser]
simply load that library and use it
$this->load->library('your_library');
$this->your_library->your_function();

El Forum

[eluser]imn.codeartist[/eluser]
Better create a helper file using _helper suffix and place it in the helper folder

which is system/application/yourfile_helper.php

El Forum

[eluser]CroNiX[/eluser]
Yes if its straight functions load as a helper as dixcoder suggests. If its a class load it as a library.

El Forum

[eluser]mjsilva[/eluser]
Imaging that your file is called my_functions.php

1) place it in application/helpers rename it my_functions_helper.php
2) go to autoload.php under application/config, and auto-load it by adding your helper name to $autoload['helper'] array.
Code:
$autoload['helper'] = ('my_functions_helper');

And that's it, after doing this you can call your function everywhere.

El Forum

[eluser]kakawett[/eluser]
That helped me too, thanks