我有以下字段(由CakePHP 3的HtmlHelper::input
方法创建),如下所示:
<input type="text" name="date" class="form-control datepicker boardroombookingdate" required="required" id="date">
此字段被设置为带有以下javascript代码的引导日期选择器:
$('#date').datetimepicker({
dayViewHeaderFormat : 'MMMM YYYY',
format : 'YYYY-MM-DD',
minDate : new Date()
});
当我提交表单并调试$this->request->data
时,我得到了这个:
\src\Controller\BoardroomBookingsController.php (line 48)
[
'employee_id' => '182',
'name' => 'sdgsdfg',
'boardroom_id' => '9',
'date' => '2016-11-07',
'start_time' => '07:00',
'end_time' => '07:00',
'client_type' => 'internal',
'clients' => '',
'notes' => 'a'
]
此处的日期是使用日期选择器选择的正确日期。
但是,当我运行以下内容时:
$boardroomBooking = $this->BoardroomBookings->newEntity();
if ($this->request->is('post')) {
$boardroomBooking = $this->BoardroomBookings->patchEntity($boardroomBooking, $this->request->data);
}
运行debug($boardroomBooking)
,我得到以下内容:
// Focusing on the date input here as that is where the issue lies
\src\Controller\BoardroomBookingsController.php (line 50)
object(App\Model\Entity\BoardroomBooking) {
'date' => object(Cake\I18n\FrozenDate) {
'time' => '1970-11-07T00:00:00+00:00',
'timezone' => 'UTC',
'fixedNowTime' => false
}
}
由于某种原因,年份变为1970年。这只发生在我的实时环境中而不是我的本地主机上。有什么理由会发生这种情况,我该如何解决?