Yii Framework Forum: beforeValidate - Yii Framework Forum

Jump to content

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

beforeValidate How to differentiate between old and new? Rate Topic: -----

#1 User is offline   mintao 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 62
  • Joined: 02-December 09
  • Location:Munich, Germany

Posted 15 May 2010 - 05:42 PM

This time - a simple problem:

public function beforeValidate();


When making use of one of these great before(...) or after(...) hooks in the CActiveRecord, how can I differentiate between the "old" data in the DB and the "new" data trying to overwrite the old?

I'm looking for sth like:

/**
 * Raise event informWebmaster if a user changed his email - JUST AS EXAMPLE
 */
public function beforeValidate()
{
    if ($this->OLD->email !== $this->email) {
        $event = new CModelEvent($this);
        $this->informWebmaster($event);
    }
    return parent::beforeValidate();
}

0

#2 User is offline   jonah 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 733
  • Joined: 27-November 08
  • Location:California (US)

Posted 15 May 2010 - 06:00 PM

Yii does not handle this for you

I recommend storing the value of the attribute(s) in afterFind(), then in beforeValidate() you can compare the stored/old value(s) to the new value(s)
http://php-thoughts.cubedwater.com - my bloggings about Yii
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