简体   繁体   English

在日历中显示事件| 代码点火器

[英]display event in calendar | codeigniter

My code is work fine in add new event to sql database .我的代码在向 sql 数据库添加新事件方面工作正常。

but Not display the event stored in sql inside the calendar.但不显示日历内存储在 sql 中的事件。

I WANT TO DISPLAY THE EVENT INSIDE THE CALENDAR我想在日历中显示事件

JS 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');

    },

Controller控制器

  function getCalender ()
  {

   $events=$this->Shedule_model->getCalender();
  echo json_encode($events);

Model模型

  function getCalender ()
  {

       $this->db->select("*");  
       $this->db->from("tbl_schedule");  
      $query = $this->db->get();
      return $query->result(); 
     }

Your controller must return a JSON output with a specific format.您的控制器必须返回具有特定格式的 JSON 输出。 For example:例如:

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

I SOLVED MY PROBLEM BY MY SELF我自己解决了我的问题

MODEL模型

 $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 - ADD EVENT - DISPLAY EVENT - REFRESH CALENDAR 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);
           }
         });
         }  
        }
        });
        }

there is code that solves your PROBLEM有代码可以解决您的问题

 <div class="card-body"> <div id='calendar-container'> <div id='calendar' class="calendar"></div> </div> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM