Welcome Guest, Not a member yet? Register   Sign In
Global variable in a class not working (using Ajax)
#1

[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:

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


Messages In This Thread
Global variable in a class not working (using Ajax) - by El Forum - 05-28-2008, 06:58 AM
Global variable in a class not working (using Ajax) - by El Forum - 05-28-2008, 07:22 AM
Global variable in a class not working (using Ajax) - by El Forum - 05-28-2008, 08:17 AM
Global variable in a class not working (using Ajax) - by El Forum - 10-18-2008, 05:44 AM
Global variable in a class not working (using Ajax) - by El Forum - 10-18-2008, 05:58 AM



Theme © iAndrew 2016 - Forum software by © MyBB