1

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

类 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 = 新的 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();
        }
    }); 
});

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

4

1 回答 1

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();
        }
    }); 
});

于 2013-01-16T10:10:16.547 回答