Welcome Guest, Not a member yet? Register   Sign In
log action model & entity
#1

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
Reply
#2

Can I have a more detailed explanation with examples? For comparison, there are method hasChanged()
Simple CI 4 project for beginners codeigniter-expenses ( topic )
Reply
#3

(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
Reply
#4

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'); 
Simple CI 4 project for beginners codeigniter-expenses ( topic )
Reply
#5

As for your log files please see this:

CodeIgniter 4 User Guide - Modeling Data - Using CodeIgniter's Model - Callbacks
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#6

(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 ?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB