[英]display event in calendar | codeigniter
我的代碼在向 sql 數據庫添加新事件方面工作正常。
但不顯示日歷內存儲在 sql 中的事件。
我想在日歷中顯示事件
JS
$(document).ready(function() {
var myCalendar = $('#calendar').fullCalendar({
events: "<?php echo base_url('Shedule/getCalender/')?>",
type: 'GET',
defaultDate: '2018-09-28',
selectable: true,
selectHelper: true,
select: function(start, end) {
var title = prompt('Event Title:');
if (title) {
var eventData = {
title: title,
start: start.format(),
end: end.format()
};
$.ajax({
url: "<?php echo base_url('Shedule/addToCalendar/')?>",
type: 'POST',
data: eventData,
success: function(result) {
myCalendar.fullCalendar('refetchEvents');
},
控制器
function getCalender ()
{
$events=$this->Shedule_model->getCalender();
echo json_encode($events);
模型
function getCalender ()
{
$this->db->select("*");
$this->db->from("tbl_schedule");
$query = $this->db->get();
return $query->result();
}
您的控制器必須返回具有特定格式的 JSON 輸出。 例如:
{
events: [
{
title: 'Event1',
start: '2011-04-04'
},
{
title: 'Event2',
start: '2011-05-05'
}
]
}
我自己解決了我的問題
模型
$this->db->select("`startdate` AS `start`, `enddate` AS `end`, `visittype AS `title`");
$this->db->from("tbl_schedule");
$query = $this->db->get();
return $query->result();
AJAX - 添加事件 - 顯示事件 - 刷新日歷
$(document).ready(function() {
refresh_calendar();
});
function refresh_calendar() {
var myCalendar = $('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
events: "<?php echo base_url('Shedule/getCalender/')?>",
type: 'GET',
defaultDate: '2018-09-28',
selectable: true,
selectHelper: true,
success: function(result){
$('#calendar').fullCalendar(result);
}
select: function(start, end) {
var title = prompt('Event Title:');
if (title) {
var eventData = {
title: title,
start: start.format(),
end: end.format()
};
$.ajax({
url: "<?php echo base_url('Shedule/test/')?>",
type: 'POST',
data: eventData,
success: function(result) {
myCalendar.fullCalendar('refetchEvents');
},
error: function(xhr, status, msg) {
alert(msg);
}
});
}
}
});
}
有代碼可以解決您的問題
<div class="card-body"> <div id='calendar-container'> <div id='calendar' class="calendar"></div> </div> </div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.