小编Yun*_*Yun的帖子

Yii isNewRecord在之前是假的吗?

我在我的模型中创建了一个beforeSave方法(扩展了GXActiveRecord),if isNewRecord永远不会被触发.我的beforeSave()被调用了.

当我打印$ this-> isNewRecord变量时,它是假的.该变量何时设置为false?我很确定这是新的

public function beforeSave(){


        if(parent::beforeSave())
            {
              if($this->isNewRecord){
                    $this->setAttribute('doc_status','new');
                    print "something";
              }else{
                  $this->setAttribute('doc_status','updated');
              }
            return  true;
            }  else { return false;

    }
Run Code Online (Sandbox Code Playgroud)

php yii

5
推荐指数
2
解决办法
2万
查看次数

标签 统计

php ×1

yii ×1