dongnan4571 2015-08-11 17:18
浏览 18
已采纳

仅当表单的任何字段发生更改时,如何更新标志

If any field of the form is unchanged then set flag to 1, and if any field of the form is changed then set flag to 0. Below is view:

<div class="row"> 
   <?php echo $form->labelEx($model,'name'); ?> 
   <?php echo $form->textField($model,'name'); ?> 
   <?php echo $form->error($model,'name'); ?> 
</div> 
<div class="row"> 
   <?php echo $form->labelEx($model,'email'); ?> 
   <?php echo $form->textField($model,'email'); ?> 
   <?php echo $form->error($model,'email'); ?> 
</div>
  • 写回答

1条回答 默认 最新

  • dongnuo6310 2015-08-12 09:28
    关注

    If you are using Y1.1

    You can do this in the model, by creating two functions function named beforeSave() and afterFind. Yii will automatically call this before saving the record, and after finding the record.

    Your strategy is to make a copy of the record when you find it, and before you update it, check the current values (from the form) with the previous values.

    class User extends CActiveRecord
    {  
        public $oldRecord;
    
        public function afterFind()
        {
            $this->oldRecord=clone $this;
            return parent::afterFind();     
        }
    
        public function beforeSave()
        {
            if ($this->oldRecord->email !== $this->email) {
                $this->changed_record_flag = true;
            }    
        }
    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思