无法获取 yii 模型函数中的变量值



无法获取函数中变量的值。当我打印$this->var时,它给了我空。在这些步骤中我缺少什么吗?

class ModelFile extends CoreModel{
public $var;
public $var2;
public function setId() {
$this->var = '123';
}
public function getId(){
$this->setId();
var_dump($this->var); //Empty
}
}

试试这个

class ModelFile extends CoreModel{
public $var;
public $var2;
public function setId() {
$this->var = '123';
}
public function getId(){
$this->setId();
var_dump($this->var); //Empty
}
}
**create an object of the above class and call the function getId() then it 
will execute and print the var**
$model = new ModelFile();
$model->getId();

最新更新