• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
global variable codeigniter

i have a file with global variable that i have used for build my webapps now i have imported this webapp in CI but i would like to use the same global variable file.

for example my file is written in this way:
$icon_add_category = $icon_folder."attach.gif";
$icon_gallery = $icon_folder."images.gif";
$icon_help = $icon_folder."help.gif";

there is a for use this variable as a global variable autoloaded withouth change the sintax?

otherwise what can i do??


[eluser]Dave Stewart[/eluser]

I'm not CI expert (yet) but you could you extend the Controller class and have your now global variables be set as class/instance variables in the constructor? Then you subclass that Controller for all you other controllers.

Hopefully there's an even cleaner way though.

You can always define a constant in the ./application/config/constant.php file that'll be available throughout your entire application.

define('ICON_ADD', $icon_folder . 'attach.gif');
define('ICON_GALLERY', $icon_folder . 'images.gif');
define('ICON_HELP', $icon_folder . 'help.gif');

Then anywhere in your application, you can just reference one of those constants when you need them.

ok but in this way i need some setting in autoload? or this variable are loaded automaticaly?


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.