Setting default time for timedate field
I have a datetime field 'post_date' for a model. It uses the date/time picker, but when left blank, I want it to default to the current timestamp. The date works, but the time is 00:00:00. In on_before_clean and on_before_post, I have this:
if (empty($values['post_date']))
{
$values['post_date'] = datetime_now();
}
Comments
Severity: Notice
Message: Undefined property: CI_Exceptions::$load
Filename: _blocks/header.php
Line Number: 23
Fatal error: Call to a member function view() on a non-object in C:\xampp\htdocs\project\fuel\application\views\_blocks\header.php on line 23
function on_before_clean($values) { if (empty($values['post_date'])) { $values['post_date'] = datetime_now(); } return $values; } function on_before_post($values) { if (empty($_POST['post_date'])) { $_POST['post_date'] = datetime_now(); } return $values; }
Sorry to have you download the latest. There were some issues a few releases back that I thought may have been the issue.
function on_before_clean($values) { if (empty($values['post_date'])) { $values['post_date'] = datetime_now(); } elseif ($values['post_date'] == date('Y-m-d H:i:s', strtotime('today midnight')) && empty($values['post_date_hour'])) { $values['post_date'] = datetime_now(); } return $values; }
$_POST['new_file_name'] = url_title(date('Y-m-d', strtotime($_POST['post_date'])).'-'.captionShort($_POST['content']), 'dash', TRUE);
Fixed the issue doing this:
function on_before_post($values) { $post_date = (empty($_POST['post_date'])) ? date('Y-m-d') : $_POST['post_date']; $_POST['new_file_name'] = url_title(date('Y-m-d', strtotime($post_date)).'-'.captionShort($_POST['content']), 'dash', TRUE); return $values; }
And setting $values['post_date'] = datetime_now(); in on_before_clean or on_before_save works fine. Thanks!