/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded */ public function loadModel($id) { $model = Translog::model()->findByPk((int) $id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function afterSave($event) { $newattributes = $this->Owner->getAttributes(); if (!$this->Owner->isNewRecord) { // new attributes $oldattributes = $this->getOldAttributes(); // compare old and new foreach ($newattributes as $name => $value) { if (!empty($oldattributes)) { $old = $oldattributes[$name]; } else { $old = ''; } if ($value != $old) { //$changes = $name . ' ('.$old.') => ('.$value.'), '; $log = new Translog(); $log->username = Yii::app()->user->id; $log->model = get_class($this->Owner); $log->useraction = 'CHANGE'; $log->createddate = new CDbExpression('NOW()'); $log->fieldname = $name; $log->fieldnewvalue = $value; $log->save(); } } } else { foreach ($newattributes as $name => $value) { $log = new Translog(); $log->username = Yii::app()->user->id; $log->model = get_class($this->Owner); $log->useraction = 'CREATE'; $log->createddate = new CDbExpression('NOW()'); $log->fieldname = $name; $log->fieldnewvalue = $value; $log->save(); } } }