xch683
(Xch683)
1
Hi,
I tried using global variable in Yii controller class.
But the global value have null value.
Someone know why?
My code:
public $a;
public actionDiag()
{
global $a;
&a = new aform(); //here I create the first value
...
}
public function requestCompleted($request)
{
global $a;
$b = $a; //$a == null <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />?
...
}
Thanks!
Keith
(Kburton)
2
I think you’re looking for a static variable, not a global one. Your code should look more like this:
public static $a;
public function actionDiag()
{
self::$a = new aform();
}
public function requestCompleted()
{
$b = self::$a;
}
Technically it doesn’t need to be static either, so you could just do this:
public $a;
public function actionDiag()
{
$this->a = new aform();
}
public function requestCompleted()
{
$b = $this->a;
}
xch683
(Xch683)
3
s
Thanks!
But also in this way the $a variable is null?
I tried this two options and all variable types (global, static and local)
but the variable equal to null in all options.
code4769
(4769mundzir)
4
I had the same problem with you. Do you already have a solution?
Try this… i hope it should work
private $a = null;
public actionDiag() {
$this->a = new aform(); //here I create the first value
}
public function requestCompleted($request)
{
$b = $this->a;
}
Hi,
Try this… i hope it should work
private $a = null;
public actionDiag() {
$this->a = new aform(); //here I create the first value
}
public function requestCompleted($request)
{
$b = $this->a;
}
Thanks
chandran nepolean