Javascript 将事件开始日期从FullCalendar更新到我的数据库会导致00:00:00
我正在使用FullCalendar,并试图在用户拖放我日历中的事件时更新事件开始时间。这是我在eventDrop回调()中使用的代码: 只要警报显示正确的事件ID和正确的开始日期(格式如下:周二2020年5月5日04:36:00),此功能就可以正常工作。还将调用“/Post/dropPost”方法,并且postId变量被正确传递 但是,当更新我的数据库时,postSchedule始终更新为“00:00:00:00” 这是我的dropPost方法:Javascript 将事件开始日期从FullCalendar更新到我的数据库会导致00:00:00,javascript,php,ajax,codeigniter,fullcalendar,Javascript,Php,Ajax,Codeigniter,Fullcalendar,我正在使用FullCalendar,并试图在用户拖放我日历中的事件时更新事件开始时间。这是我在eventDrop回调()中使用的代码: 只要警报显示正确的事件ID和正确的开始日期(格式如下:周二2020年5月5日04:36:00),此功能就可以正常工作。还将调用“/Post/dropPost”方法,并且postId变量被正确传递 但是,当更新我的数据库时,postSchedule始终更新为“00:00:00:00” 这是我的dropPost方法: public function drop
public function dropPost()
{
$data=[];
$postSchedule = $_POST['postSchedule'];
$postId = $_POST['postId'];
$droppedPost = new PostModel;
$data['id'] = $postId;
$data['postSchedule'] = $postSchedule;
$droppedPost->save($data);
}
通过阅读完整的日历文档,我的理解是,日期应始终符合ISO8601标准:。那么为什么它不能转换到我的数据库中呢
我的数据库中的postSchedule列的类型是DateTime。我终于找到了答案。我需要在info.event.start属性上使用.toISOString() 工作守则如下:
eventDrop: function(info) {
alert(info.event.id + ' was dropped on ' + info.event.start);
$.ajax({
url: '/Post/dropPost',
type: 'POST',
data: { 'postSchedule': info.event.start.toISOString(), 'postId' : info.event.id },
});
},
问题是,我认为您没有将
postSchedule
转换为正确的格式以存储在数据库中
控制器
首先,检查打印($this->input->post())
是否正在检索数据,如果是,则将数据转换为正确的格式,即
$data['postSchedule']=date(“Y-m-dh:i:s”,strotime($postSchedule))编码>然后使用类型DATETIME
将数据存储在数据库中。
希望这对你有帮助
eventDrop: function(info) {
alert(info.event.id + ' was dropped on ' + info.event.start);
$.ajax({
url: '/Post/dropPost',
type: 'POST',
data: { 'postSchedule': info.event.start.toISOString(), 'postId' : info.event.id },
});
},