Php 在日历中显示事件| codeigniter

Php 在日历中显示事件| codeigniter,php,codeigniter,Php,Codeigniter,我的代码在向sql数据库添加新事件时工作正常 但不在日历中显示存储在sql中的事件 我想在日历中显示事件 JS 模型 控制器必须返回具有特定格式的JSON输出。例如: { events: [ { title: 'Event1', start: '2011-04-04' }, { title: 'Event2', start: '2011-05-05' } ] } 我自己解决了我的问题 模型 AJAX-添加事

我的代码在向sql数据库添加新事件时工作正常

但不在日历中显示存储在sql中的事件

我想在日历中显示事件

JS

模型


控制器必须返回具有特定格式的JSON输出。例如:

{
  events: [
    {
      title: 'Event1',
      start: '2011-04-04'
    },
    {
      title: 'Event2',
      start: '2011-05-05'
    }
  ]
}

我自己解决了我的问题

模型

AJAX-添加事件-显示事件-刷新日历

$(文档).ready(函数(){
刷新日历();
});
函数refresh_calendar(){
var myCalendar=$(“#calendar”).fullCalendar({
标题:{
左:“上一个,下一个今天”,
中心:'标题',
右图:“月,agendaWeek,agendaDay”
},
事件:“”,
键入:“GET”,
违约日期:“2018-09-28”,
是的,
selectHelper:对,
成功:功能(结果){
$(“#日历”).fullCalendar(结果);
}
选择:功能(开始、结束){
var title=prompt('事件标题:');
如果(标题){
var eventData={
标题:标题,,
start:start.format(),
end:end.format()
};
$.ajax({
url:“”,
键入:“POST”,
数据:eventData,
成功:功能(结果){
myCalendar.fullCalendar('refetchEvents');
},
错误:函数(xhr、状态、消息){
警报(msg);
}
});
}  
}
});
}

有一些代码可以解决您的问题



我以前做这个是为了测试,但也不起作用$数据=数组('id'=>1,'title'=>nojoud','start'=>2018-09-28','end'=>2018-09-29',);echo json_编码($data);您忘记了test.plz中的关键“事件”。解释一下,我把事件键放在哪里了???在控制器中还是在哪里?因为我试着把它放在Controrrer和JS中。请解释一下这段代码是如何解决这个问题的
  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(); 
     }
{
  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(); 
      $(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);
           }
         });
         }  
        }
        });
        }