0

I have a file called functions.php this file contain many functions like the following

function name(){
  .......
}

function name2($arg){
  .......
}

function name3($par, $par2){
  .......
}

Etc.

That file is not a class, but contain many functions in one place.

My questions

  1. Where can I place this file to use it from any view file or controller file like a global file.
  2. Then, how to include any function from functions.php file at any view or controller file .
Lion King
  • 32,851
  • 25
  • 81
  • 143
  • 1
    You should look in the helper section, that's exactly what helpers are for – Damien Pirsy May 11 '14 at 13:08
  • What @Damien Pirsy is the way to go, however as Codeigniter is just a collection of PHP scripts, you can also include it in a file that always get's loaded like the config file. – hakre May 11 '14 at 13:08
  • I did not added my question here only after what I reviewed the user guide of codeigniter, and also I searched on the web to find anything help me, but I still don't understand how to can I do that – Lion King May 11 '14 at 14:26
  • @Ayman Safadi: Your post really helped me. thank you – Lion King May 11 '14 at 14:38

1 Answers1

0

If you need function to be accessible through your view, you should use a customise helper:

http://ellislab.com/codeigniter/user-guide/general/helpers.html

Otherwise if you need to create a function that accessible on controller it better to create your own library:

http://ellislab.com/codeigniter/user-guide/general/creating_libraries.html

assaqqaf
  • 1,575
  • 4
  • 21
  • 38