dongsun5330 2015-11-09 01:01
浏览 19
已采纳

yii更新一个属性而不使用模型保存

I need update the attribute count ($file->count) in the file model, as i have set the aftersave() function about this file model. when I update other file's attributes do save() model it will call the aftersave() later.

But when update the count attribute and save(), it need skip the aftersave().

How can I do it, Can I only save the count attribute without use save(), or set the condition on the aftersave() to skip the aftersave()

  • 写回答

1条回答 默认 最新

  • doudu3961 2015-11-09 01:04
    关注

    Use saveAttributes method.

    Saves a selected list of attributes. Unlike save, this method only saves the specified attributes of an existing row dataset and does NOT call either beforeSave or afterSave. Also note that this method does neither attribute filtering nor validation. So do not use this method with untrusted data (such as user posted data). You may consider the following alternative if you want to do so:

    http://www.yiiframework.com/doc/api/1.1/CActiveRecord#saveAttributes-detail

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

报告相同问题?