Can I also update a field while logging?
Can I also update a field while logging?
orionaselite
Posts: 49Questions: 13Answers: 4
I have the following
function logChange ( $db, $action, $id, $values ) {
//var_dump($_SESSION);
$username = $_SESSION['username'];
$desc = 'Admin with email '.$username.' has taken action '.$action.' using values '.json_encode( $values ).' on table ads in row '.$id;
$db->insert( 'logs', array(
'user_id' => $_SESSION['id'],
'description' => $desc,
'log_date' => date('c')
) );
}
->on( 'postCreate', function ( $editor, $id, $values, $row ) {
logChange( $editor->db(), 'create', $id, $values );
} )
->on( 'postEdit', function ( $editor, $id, $values, $row ) {
logChange( $editor->db(), 'edit', $id, $values );
} )
what I also need to do other then logging successful edits or creates is to set the datetime of a field in my table when either updating or creating. the field name is created_date and updated_date. in my table called ads. They need to be set to the current datetime on create or edit.
ideas?
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
I tried this
I assumed ->setValue(date('c')); would do what I needed but I get 0000-00-00 00:00:00 ideas?
my full code follows
any ideas why I keep getting 30-11--0001 00:00:00 it's as if my formatters are incorrect
My db field is of type DATETIME if that helps
Hi,
Your use of
$editor->field(...)->setValue(...)
looks spot on to me - but you have to do that inpreEdit
! InpostEdit
, the values have already been written to the database.Allan
Thanks although the issue seemed to be becase i decided to exclude the updated_date and created_date from the editor so the Generator had added ->set(false); I just included the fields in the editor and it works fine. It would be nice if I could exclude tthe fields so that the user can't edit them but ok. I can live with that