CodeIgniter Forums
How to declear global variable in Controller? - 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: How to declear global variable in Controller? (/showthread.php?tid=19914)



How to declear global variable in Controller? - El Forum - 06-22-2009

[eluser]PEN Vannak[/eluser]
Dear CodIgnitor members,

I have the problem with CodeIgnitor when I want to declear the variable in the class controller.
Could you explain me?


How to declear global variable in Controller? - El Forum - 06-22-2009

[eluser]Thorpe Obazee[/eluser]
[quote author="PEN Vannak" date="1245739774"]Dear CodIgnitor members,

I have the problem with CodeIgnitor when I want to declear the variable in the class controller.
Could you explain me?[/quote]

what do you mean by declear?


How to declear global variable in Controller? - El Forum - 06-22-2009

[eluser]tonanbarbarian[/eluser]
since every request in CI revolves around a single controller, rather than creating a global variable you can simply just create a property of the controller

i.e. if previously you wanted to create a global variable like this
Code:
global $myvar;
$myvar = 'abc';
try doing this instead
Code:
$this->myvar = 'abc';

Then if you want to access this in the model, libraries etc
Code:
$CI =& get_instance();
echo $CI->myvar;



How to declear global variable in Controller? - El Forum - 06-22-2009

[eluser]Thorpe Obazee[/eluser]
[quote author="bargainph" date="1245740029"][quote author="PEN Vannak" date="1245739774"]Dear CodIgnitor members,

I have the problem with CodeIgnitor when I want to declear the variable in the class controller.
Could you explain me?[/quote]

what do you mean by declear?[/quote]

so it's declare. I was leaning to the 'opposite of clear' option Tongue


How to declear global variable in Controller? - El Forum - 06-22-2009

[eluser]Colin Williams[/eluser]
[quote author="bargainph" date="1245740131"][quote author="bargainph" date="1245740029"][quote author="PEN Vannak" date="1245739774"]Dear CodIgnitor members,

I have the problem with CodeIgnitor when I want to declear the variable in the class controller.
Could you explain me?[/quote]

what do you mean by declear?[/quote]

so it's declare. I was leaning to the 'opposite of clear' option Tongue[/quote]

We are also "CodIgnitors" so we must be setting fish on fire...