Welcome Guest, Not a member yet? Register   Sign In
how to add a global function to my application?
#1

[eluser]kisin[/eluser]
i want to insert a function that will be available in all my site.

to be more specific, i want to add a t() function (like in drupal) that will handle all my translation needs. and i want to be able to call it directly from anywhere.

how can i do this?
#2

[eluser]zdknudsen[/eluser]
That depends how you define "anywhere".

If you make a helper with said function and autoload it, you would have access to it pretty much everywhere.
#3

[eluser]kisin[/eluser]
thanks.
at first i tried to use the pre_system hook but i couldnt add a function just call it.
so the helper solution is great!
#4

[eluser]Lone[/eluser]
I always like to think of Helper files as you usual 'functions.php' files that were common in the past. But only try to use them sparingly - generally speaking you should be able to fit most of your functions under libraries/models.

Libraries/classes then enhance this your function range as you have another level to call them by rather then some nasty long function names eg.

Code:
// Old way
user_get_details($id);
// CI / Class way
$user->get_details();




Theme © iAndrew 2016 - Forum software by © MyBB