dongshi2836 2017-02-22 08:09
浏览 37
已采纳

Updatebypk没有在yii中调用afterSave

I have updatebypk in my controller to update a Model but i found that updatebypk not calling Yii afterSave function.It is the behaviour of updatebypk

Model::updateByPk($key,array('content'=>$content))// it is updating conten 

Model.php

 protected function afterSave()
    {
      parent::afterSave();
       if(!$this->isNewRecord){
        $this->update_time = time();
       $this->update_by = Yii::app()->user->getId();
       $this->save(false);

      }


    }
  • 写回答

1条回答 默认 最新

  • doumiao0498 2017-02-22 08:13
    关注

    updateByPk() is using database query directly and not model's save() method and this is why it's not calling afterSave(). This is by design.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?