Yii Framework Forum: Some Way To Update Only The Chanched Form Fields. - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Some Way To Update Only The Chanched Form Fields.

#1 User is offline   NCS_One 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 56
  • Joined: 24-August 11

Posted 29 January 2013 - 01:17 AM

Hi,

Maybe declare a new property like:

public $changedAttributes = array();


then when doing:

$model = new MyModel;
$model->attributes = $_POST['MyModel'];


on CActiveRecord::setAttributes only have to check if value is equal, if it is not equal add that attribute to $changedAttributes.

than user only have to do:

$model->update($model->changedAttributes);

0

#2 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,782
  • Joined: 17-January 09
  • Location:Russia

Posted 29 January 2013 - 04:29 AM

It's builtin in Yii2 AR.
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#3 User is offline   NCS_One 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 56
  • Joined: 24-August 11

Posted 30 January 2013 - 05:31 PM

Nice :)
Thanks.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users