05-28-2008, 06:58 AM
[eluser]mvdg27[/eluser]
Hi guys,
I'm not sure if I made a coding error, or if CI handles global vars in a class differently or that using Ajax changes things, but somehow I'm not able to share a variable across functions in the same class.
My code:
First the function foo1 is called and it successfully alerts the my_global_var. After, the function foo2 is called, but then my_global_var is not available anymore ..
Anyone have an idea why?
Cheers, Michiel
Hi guys,
I'm not sure if I made a coding error, or if CI handles global vars in a class differently or that using Ajax changes things, but somehow I'm not able to share a variable across functions in the same class.
My code:
Code:
class Justtesting extends Controller {
var $my_global_var;
function Justtesting() {
parent::Controller();
$this->xajax->registerFunction(array('foo1',&$this,'foo1'));
$this->xajax->registerFunction(array('foo2',&$this,'foo2'));
$this->objResponse = new xajaxResponse();
$this->xajax->processRequest();
}
function foo1($var) {
$this->my_global_var = $var;
$this->objResponse->alert($this->my_global_var);
// code here ...
return $this->objResponse;
}
function foo2() {
$this->objResponse->alert($this->my_global_var);
return $this->objResponse;
}
}
First the function foo1 is called and it successfully alerts the my_global_var. After, the function foo2 is called, but then my_global_var is not available anymore ..
Anyone have an idea why?
Cheers, Michiel