CodeIgniter Forums
log action model & entity - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=31)
+--- Thread: log action model & entity (/showthread.php?tid=88442)



log action model & entity - devo - 09-09-2023

hii guys, i want to ask how and what is the best way to log inserted data, updated data compare before and after update, and deleted data
i use model entity


RE: log action model & entity - ozornick - 09-09-2023

Can I have a more detailed explanation with examples? For comparison, there are method hasChanged()


RE: log action model & entity - devo - 09-09-2023

(09-09-2023, 10:00 AM)ozornick Wrote: Can I have a more detailed explanation with examples? For comparison, there are method hasChanged()

i mean is log activity action
when i insert data it wil insert and save to my log table
and when i update data it will just save updated data ex: i have field username - name and i change the name so the update will compare old value and new value any change will like this {"from" => 'oldvalue', 'to' => 'newvalue'}

sorry my english is bad


RE: log action model & entity - ozornick - 09-09-2023

Before updating, check the changed properties of the entity and save somewhere (log, other table)

PHP Code:
<?php

// Controller, Something like this
$entity $model->get(15);
$entity->setText('new text');

if (
$entity->hasChanged('text')) {
    // save to log, table
}

$model->update($entity'id'); 



RE: log action model & entity - InsiteFX - 09-09-2023

As for your log files please see this:

CodeIgniter 4 User Guide - Modeling Data - Using CodeIgniter's Model - Callbacks


RE: log action model & entity - devo - 09-14-2023

(09-09-2023, 09:50 PM)InsiteFX Wrote: As for your log files please see this:

CodeIgniter 4 User Guide - Modeling Data - Using CodeIgniter's Model - Callbacks


so if i use after update model callback how can i compare old data and new data ?