intersvyaz/yii-old-attribute-behavior

Yii old attribute behavior.

v1.0.0 2015-03-23 14:44 UTC

This package is auto-updated.

Last update: 2024-04-08 04:52:58 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License

Example usage:

class User extends CActiveRecord
{
  /**
   * @inheritdoc
   */
	public function behaviors()
	{
		return array_merge(
			parent::behaviors(),
			[
				'oldBehavior' => ['class' => Intersvyaz\Behavior\OldAttributesBehavior::class],
			]
		);
	}
	
	/**
	 * @inheritdoc
	 */
	protected function afterSave()
	{
	  if ($this->isModified('username')) {
	      // some your logic
	      $oldValue = $this->old->username;
	      // or
	      $oldValue = $this->oldAttributes['username'];
	      // new value in $this->username
	  }
	  parent::afterSave();
	}
}