![]() |
Able to access global variable, but ... - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Able to access global variable, but ... (/showthread.php?tid=3805) |
Able to access global variable, but ... - El Forum - 10-22-2007 [eluser]cinewbie81[/eluser] Hi all, I have a helper file named : "setting_helper.php" as following: Code: <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); The following is my controller class: Code: <?php How come when i call Runsetup function, echo __VARIABLE1__ will print me "variable1", but echo $var2 will give me nothing ?? By right it should return me the value "variable2" as i already decraed it as global variable .. anyone ?? Able to access global variable, but ... - El Forum - 10-22-2007 [eluser]crikey[/eluser] Look at your global variable declaration in Runsetup - gloabl should be spelt 'global'. Able to access global variable, but ... - El Forum - 10-22-2007 [eluser]Jatinder Thind[/eluser] Even after fixing the "gloabl" typo, it won't work. To know why, you have to first understand how a helper is loaded. When you call Code: $this->load->helper(array('url', 'setting')); The helper() function simply includes the setting_helper.php file. Therefore $var2 will be available only within the local context of helper() function and won't be visible outside this function. Change your helper as below at it will work: Code: <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); Able to access global variable, but ... - El Forum - 10-22-2007 [eluser]cinewbie81[/eluser] thx a lot Jatinder Thind .. it works now ![]() Able to access global variable, but ... - El Forum - 10-23-2007 [eluser]cinewbie81[/eluser] Problem solved .. but one more question, how am i goin to do it if the variable is an array ? I try: Code: <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); and my controller class: Code: <?php When i call Runsetup function, it generate me the error : "Message: Undefined index: apple" .. any idea ? Able to access global variable, but ... - El Forum - 10-23-2007 [eluser]xwero[/eluser] [quote author="cinewbie81" date="1193137997"] Code: <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); [/quote] You have set up strings instead of an array Code: <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); Able to access global variable, but ... - El Forum - 10-23-2007 [eluser]cinewbie81[/eluser] [quote author="xwero" date="1193138753"][quote author="cinewbie81" date="1193137997"] Code: <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); [/quote] You have set up strings instead of an array Code: <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); not working still even though i use your code ![]() Able to access global variable, but ... - El Forum - 10-23-2007 [eluser]Jatinder Thind[/eluser] This will work: Code: <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); |