Field populated with mysql row id if field is empty at row create time
Field populated with mysql row id if field is empty at row create time
I want to have a field that will be populated by the php server code at row creation time, but this field needs to contain the mysql row id in it - so the value won't be available until the row creation has completed.
Is there some way to hook into post row creation on the php side ?
The actual string I want to construct needs to be stored in the row so that I can search for it later - it will be a unique string for that row. So I can't simply use Field->getFormatter() and construct it at read time as I'm doing server side searching, and this string would not be in the database if it is created on the fly by getFormatter() as opposed to being in the DB actual.
Thus it will require another write to the record at row creation time - once to do the create, and secondly to update to give this new field a value.
Any ideas ? thanks.
This question has an accepted answers - jump to answer
Answers
Is this editor? If not, there is no PHP side.
Only way would be to make an ajax call in the
rowCreated
, atleast that i know ofYes this is editor with a PHP backend.
If I wasn't using server side processing I could use.
but this won't work for server side as this value is calculated based on the row and presented to the web page, but not stored in the DB where the search needs to find it.
Looks like I might be able to use some new features in PHP event handlers.
http://editor.datatables.net/manual/php/events
postCreate - Triggered immediately after a new row has been created
Here is the solution I came up with. It can be done all in the PHP end, neatly after the new record has been created. It uses some features recently added to the PHP backend support for Editor. v1.5 I believe.
For more info see
http://editor.datatables.net/manual/php/events
and
http://editor.datatables.net/docs/1.5.1/php/class-DataTables.Database.html
Hi,
Great to hear you found a solution - yes, a
postCreate
hook is going to be the best way to get this to work! Nice use of that functionality :-)Allan