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

#1
[eluser]italoc[/eluser]
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:
Code:
$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??

thanks..

#2
[eluser]Dave Stewart[/eluser]
http://ellislab.com/codeigniter/user-gui...onfig.html

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.

#3
[eluser]AgentPhoenix[/eluser]
You can always define a constant in the ./application/config/constant.php file that'll be available throughout your entire application.

Code:
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.

#4
[eluser]italoc[/eluser]
ok but in this way i need some setting in autoload? or this variable are loaded automaticaly?

thanks...


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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