【问题标题】:Unable to get value of variable in yii model function无法在 yii 模型函数中获取变量的值
【发布时间】:2018-06-01 02:39:29
【问题描述】:

无法在函数中获取变量的值。当我打印$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
 }

}

【问题讨论】:

    标签: php yii model


    【解决方案1】:

    试试这个

    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();
    

    【讨论】:

      猜你喜欢
      • 2017-05-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-03
      • 1970-01-01
      • 1970-01-01
      • 2014-08-10
      • 1970-01-01
      相关资源
      最近更新 更多