set last update time in php when cell changes
set last update time in php when cell changes
I'm sure there is a really elegant way to have the PHP set the time() whenever a write to any field in a row occurs.
I have a field of type datetime in mysql that is only in the Editor fields and not in the dataTable object.
There is the section in the example code showing how to format it on read.
Field::inst( 'tablename.lastupdated')
->set( false )
->getFormatter( 'Format::date_sql_to_format', 'jS F Y' )
but I'm wondering where to do the write to tablename.lastupdated
somehow in the
->process( $_POST )
->data();
block ?
thanks.
This question has an accepted answers - jump to answer
Answers
Hi,
If you are using the 1.4 libraries (which are currently in beta, but at a feature for exactly this situation!) you can use:
i.e. the value to be used when setting is given by
setValue()
.With the 1.3 libraries, it is possible, but a bit more complicated as you need to modify the
$_POST
array when submitting the value:Hopefully you will agree that the 1.4 method is much easier :-).
The other thing to note is that you have
set( false )
at the moment. That will stop Editor ever writing to this field, which doesn't sound like what you want.Allan
Great to hear that it will be so easy.
I have dataTables.editor.js 1.4.0 beta but get invalid json because of
Call to undefined method DataTables\Editor\Field::setValue()
It sounds like you might have the 1.4 beta Javascript, but possibly not the PHP files. Might that be correct? The
setValue()
method is defined in theField.php
file.Allan
I have the mysql field set to DATETIME as setValue is definitely writing a new value each time the row is touched - but with and without the getFormatter call I always get null as the value returned.
How can I easiest debug the php code to see why ?
Hi,
One option is to use
getFormatter
with an anonymous function that logs the data to a file:that won't do any formatting, but it will log what has been read from the database to the file
/tmp/a
which you cantail -f
watch as you load the page.Allan
hmmmm the setVal() value is definitely getting there to the DB, and the getFormatter is showing null for $val so it looks like reading it back is not working.
I think you should be using MySQL's timestamp rather than datetime. That way you don't need to write to that field at all.
Well dare I say it but - show me the code - does anyone have a working set of configuration for this feature. Nothing seems to work for me.
If you remove the get formatter, what happens? Do you get the SQL ISO8601 timestamp or something else?
Allan
There was a bug in DT that is now fixed so this item can be closed.