fullcalendar json无效

时间:2013-01-14 19:29:33

标签: fullcalendar

我很难尝试在fullcalendar上填充事件,以下是我的代码,试图从mysql中获取数据

class mycalendarleaves扩展Generic {  function calendar_LeaveDetails(){

$year = date('Y');
$month = date('m');
$this->user_id = $_SESSION['user_id'];
$params = array( ':user_id' => $this->user_id );
$stmt   = parent::query("SELECT * FROM messages WHERE TYPE = 'leave' AND leave_status='approved' AND sender_id = :user_id;", $params);

while($value = $stmt->fetch()) :    
    $_SESSION['cal_data']  = array(
            'id'    => $value['id'],
            'title' =>  $value['sender_name'],
            'start' =>  "$year-$month-10"
            );
    endwhile;
}

}

echo json_encode($ _ SESSION ['cal_data']);

$ mycalendarleaves = new mycalendarleaves();

这是脚本

<script type='text/javascript'>
$(document).ready(function() {
    $('#calendar').fullCalendar({
        editable: true,
        events: "calendar.php",
        eventDrop: function(event, delta) {
            alert(event.title + ' was moved ' + delta + ' days\n' +
                '(should probably update your database)');
        },
        loading: function(bool) {
            if (bool) $('#loading').show();
            else $('#loading').hide();
        }
    }); 
});

我没有收到任何错误,如果没有数据,日历仍然显示为空白。我做错了什么?

1 个答案:

答案 0 :(得分:1)

我得到了它的工作,因为其他人遇到问题可能会对他们有所帮助。

以下是我从mysql中获取数据的函数

 function calendar_EventDetails(){


$year = date('Y');
$month = date('m');
$this->id = $_SESSION['id'];
$params = array( ':id' => $this->id );
$stmt   = parent::query("SELECT * FROM TABLENAME WHERE TYPE = 'event' AND status='approved' AND id = :id;", $params);

unset($_SESSION['events']);
while($value = $stmt->fetch()) :

    $_SESSION['events'][]  = array(
            'id'    => $value['id'],
            'title' =>  $value['name'],
            'start' =>  "$year-$month-10"

            );
    endwhile;
}

以下是调用上述函数所在的php文件的脚本

<script type='text/javascript'>
$(document).ready(function() {
    $('#calendar').fullCalendar({
        editable: true,
        events: "calendar.php",
        eventDrop: function(event, delta) {
            alert(event.title + ' was moved ' + delta + ' days\n' +
                '(should probably update your database)');
        },
        loading: function(bool) {
            if (bool) $('#loading').show();
            else $('#loading').hide();
        }
    }); 
});