How do I add a non-editable field that contains the field of current time??
⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠
Posted 26 March 2014 - 21:16 PM
How do I add a non-editable field that contains the field of current time??
Posted 27 March 2014 - 12:30 PM
I have 2 DATETIME columns in my table, named "created" and "modified".
As I want the value to be generated automaticly, and as well as modified updating every time the post is updated, while created only added once, I did like this:
public function _callback_fix_created($p) { $date_time = date("Y-m-d H:i:s"); $p['created'] = $date_time; $p['modified'] = $date_time; return $p; } public function _callback_fix_modified($p) { $p['modified'] = date("Y-m-d H:i:s"); return $p; } public function index() { $crud->field_type('created','invisible'); $crud->field_type('modified','invisible'); $crud->callback_before_insert(array($this,"_callback_fix_created")); $crud->callback_before_update(array($this,"_callback_fix_modified")); }
You could set another field type of course, I have chosen to have my fields completely hidden in the add and edit form.