CodeIgniter Forums
HELP! Prolbem of global variable - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: HELP! Prolbem of global variable (/showthread.php?tid=50031)



HELP! Prolbem of global variable - El Forum - 03-11-2012

[eluser]Unknown[/eluser]
I'm a beginner of CI, I declare a globals variable in controller like this

<?php
$aaa='0';

class Test extends CI_Controller {

function __construct()
{
parent::__construct();

}

...

then i change this global variable in one of the functions in this controller

$GLOBALS['aaa']=$this->input->post('bbb');

in this function, i have checked the 'aaa' and the content of it has been changed to the value of 'bbb' which is input by the user.

But when i use 'aaa' in other function, the value is unchanged, it is still 0 as initialized. what can i do if I want to use the new value of it? Pls give some helps, thx~


HELP! Prolbem of global variable - El Forum - 03-12-2012

[eluser]InsiteFX[/eluser]
Maybe if you move it into the class it will work!



HELP! Prolbem of global variable - El Forum - 03-12-2012

[eluser]Aken[/eluser]
I suggest you learn more about variable scopes, class properties, and other basic PHP items before venturing into CodeIgniter. Otherwise you're setting yourself up to do a lot of poor coding.