带有SQL的EventSources在Fullcalendar中不起作用

时间:2018-12-06 12:53:50

标签: javascript php fullcalendar

您好,我想尝试使用EventSources通过sql在同一日历中获取多个事件,但是当我尝试像fullcalendar docs那样执行日历时,日历将变为空白。我究竟做错了什么?这是我的Callendar代码

                      <script type="text/javascript">
                    document.addEventListener('DOMContentLoaded', function() { // DOMContentLoaded zorgt ervoor dat eerst de html laad
                      var calendarEl = document.getElementById('calendar'); // grab element reference

                      var calendar = new FullCalendar.Calendar(calendarEl, {
                        // Opties in fullcalendar
                        eventLimit: true,
                        locale: 'nl',
                        buttonText: {
                          month: 'Maand',
                          agendaDay: 'Dag',
                          agendaWeek: 'Week',
                          today: 'Vandaag',
                          listMonth: 'Lijst'
                        },
                        header: {
                          left: 'prev,next today',
                          center: 'title',
                          right: 'listMonth,month,agendaWeek,agendaDay'
                        },
                        eventSources: [
                          '/sql.php',
                          '/availability.php'
                        ]
                      });

                      calendar.render();
                    });
                  </script>

1 个答案:

答案 0 :(得分:2)

您的php文件必须将事件作为json供稿返回

示例:

<?php
$event_array = array();

while ($row = $getCalenderItems->fetch()) {

    $event_array[] = array(
        "title" => $row['Docentnaam'] . ' ' . $row['Onderdeelnaam'] . ' ' . $row['Opleidingnaam'] . ' ' . $row['LocatiePlaats'],
        "start" => new Date($row['Start']),
        "end" => new Date($row['Eind'])

    );
}

echo json_encode($event_array);


?>

调整您的php文件,以将json feed返回到日历源,如上所示。