Answer the question
In order to leave comments, you need to log in
How to implement ticket change history in Yii2?
There was such a need to keep track of who changes applications. While it is implemented like this: there is a logs table, we save it when accessing the controller for changes:
public function actionComment()
{
$log = new Logs();
$log->task_id = $id;
$log->user_id = Yii::$app->user->id;
$log->time = date('Y-m-d H:i:s');
$log->new_data = $comment;
$log->action = 'Комментарий';
if(!$log->save(false)) {
return false;
}
//Далее сохраняем данные
Answer the question
In order to leave comments, you need to log in
If you want to implement this functionality more correctly, then you should not shove it into the controller. he just doesn't belong there. The controller only needs to process the user's request, interact with the business logic and presentation layer.
Implement a separate component/behavior that will:
1. Catch data saving events in models
2. Get record objects themselves from these events
3. Remove changed data from the object using the getDirtyAttributes() method 4. Form
the log object itself and save it
but before With this, I would recommend you to look for ready-made solutions, because. for this task - they are
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question