我确实对此进行了很多搜索,但是仍然没有解决我的问题。我正在创建一个日历(使用插件fullcalendar并使用codeigniter作为后端),以显示游览及其特定的时间跨度。因此,在这种情况下,活动的标题将是旅行名称,并且在旅行期间,将获取开始和结束日期。
我已经成功地将数据插入到数据库中,只是事件没有出现在其各自的日期上。
到目前为止,这些是我编写的代码:
控制器:Calendar.php
function view_tours(){
$this->load->model('Calendar_model');
$tours = $this->Calendar_model->getTours();
echo json_encode($tours);
}
function add_tour(){
$sdate = $this->input->post('start_date'); //start date
$edate = $this->input->post('end_date'); //end date
if($this->form_validation->run() == TRUE){ //column name in db=>name in form
$tour = array('tour_name' => $this->input->post('tour_name'),
'start_date' => date('Y-m-d', strtotime($sdate)),
'end_date' => date('Y-m-d', strtotime($edate)),
'slots' => $this->input->post('slots'),
'rate' => $this->input->post('rate'),);
$this->Calendar_model->insert_tour($tour);
echo 'success';
}
else {
redirect(base_url().'Calendar');
echo "error";
}
}
型号:Calendar_model.php
public function getTours(){
$query = $this->db->get('tours');
return $query -> result_array();
}
function insert_tour($tour){
$this->db->insert('tours', $tour);
return $this->db->insert_id();
}
查看:home.php(这是html文件)
<div id="AddModal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span> <span class="sr-only">close</span></button>
<h4 id="modalTitle" class="modal-title"> Add a Tour </h4>
</div>
<div id="modalBody" class="modal-body">
<?php
echo validation_errors();
?>
<form class="form-horizontal" id="crud-form" method="POST" action="<?php echo base_url();?>Calendar/add_tour">
<div class="form-group">
<label class="col-md-4 control-label" for="tour_name">Tour Name</label>
<div class="col-md-4">
<input type="text" class="form-control" id="tour_name" name="tour_name"/>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label" for="start_date">Start Date</label>
<div class="col-md-4">
<input type="date" class="form-control" id="start_date" name="start_date"/>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label" for="end_date">End Date</label>
<div class="col-md-4">
<input type="date" class="form-control" id="end_date" name="end_date"/>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label" for="slots">Slots</label>
<div class="col-md-4">
<input type="text" class="form-control" id="slots" name="slots"/>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label" for="rate">Rate</label>
<div class="col-md-4">
<input type="text" class="form-control" id="rate" name="rate"/>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label" for="color">Color</label>
<div class="col-md-4">
<input id="color" name="color" type="text" class="form-control input-md" readonly="readonly" />
<span class="help-block">Click to pick a color</span>
</div>
</div>
<button type="submit" class="btn btn-primary"> Add Tour</button>
</form>
</div> <!--end of modal body-->
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
我最近对此进行了编辑,但这不起作用。
JS文件:main.js我尝试使用$ .ajax选项获取数据,但是当我这样做时,日历本身不会出现。代码有什么问题?我只是ajax的初学者。
events: {
url: base_url+'Calendar/view_tours',
type: 'POST',
data{
title: tour_name,
start: start_date,
end: end_date
},error: function(){
alert('error in fetching from database!');
}
}, //end of events
我只是粘贴了一段js。我知道日历是“以某种方式”从数据库中检索数据,因为我可以看到事件,但对于添加的所有事件,它仅实时显示在当前日期并显示当前时间。而且我添加了一个工具提示,以查看巡回名称(标题)是否正在被读取,确实如此。
实际结果是这样的:单击以查看图像
问题摘要:事件不在各自的日期中,添加的时间是实时的。
因此,看来您的问题是您的URL返回的JSON对象包含fullCalendar的无法识别的数据。因此,您必须获取以下事件:
events: base_url+'Calendar/view_tours',
并更改数据库的列从tour_id
到id
,tour_name
到title
,start_date
到start
和end_date
到end
。这将创建正确的JSON对象。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句