PHP code example of intersvyaz / yii-old-attribute-behavior
1. Go to this page and download the library: Download intersvyaz/yii-old-attribute-behavior library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
intersvyaz / yii-old-attribute-behavior example snippets
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();
}
}