fullcalendar不呈现事件

时间:2016-06-17 16:46:37

标签: jquery fullcalendar symfony

我正在使用symfony的完整日历。但是事件没有呈现。我尽力了。

控制器代码

  /**
 * @Route("/get-booking-to-calendar/{id}", name="booking-to-calendar")
 */
public function BookingCalendarAction($id)
{
    $em=$this->getDoctrine()->getManager();

    $field = $em->getRepository('AppBundle:Field')->find($id);

    $bookings= $em->getRepository('AppBundle:Booking')->findBy(array('field_booking' => $field->getId()));

    foreach($bookings as $booking)
    {
        $booking_array[] = array(
            'id' => $booking->getId(),
            'title' => $booking->getDuration(),
            'start' => $booking->getStartTime(),
            'end' => $booking->getEndTime(),
            'allDay'=>true,
        );

    }
    $response = new Response(json_encode($booking_array));
    $response->headers->set('Content-Type', 'application/json');
    return $response;


}

Twig

 <script>
    $(document).ready(function() {

        var calendar = $('#calendar').fullCalendar({
            editable: true,
            timeFormat: 'h:mm',
            allDaySlot:false,

            slotDuration : '00:15:00',
            header: {
                left: 'prev,next today',
                center: 'title',
                right: 'month,agendaWeek,agendaDay'
            },

            events: "{{ path ('booking-to-calendar',  {'id':field_id}) }}",
            // Convert the allDay from string to boolean

            eventRender: function(event, element, view) {
                if (event.allDay === 'true') {
                    event.allDay = true;
                } else {
                    event.allDay = true;
                }
            },

        });
    });

</script>

,我的json回复是

[{"id":2,"title":4,"start":{"date":"2016-06-18 11:00:00.000000","timezone_type":3,"timezone":"Europe\/London"},"end":{"date":"2016-06-18 12:00:00.000000","timezone_type":3,"timezone":"Europe\/London"},"allDay":true}]
似乎eveything是好的。但事件并未出现在日历上。

这里是html render

click to view image

2 个答案:

答案 0 :(得分:0)

您是否尝试过使用eventDataTransform挂钩?手动填充事件对象,看看是否仍然出现问题。 Fullcal没有正确解析我的开始/结束ISO8901,我遇到了同样的问题。我必须将我的JSON开始/结束数据解析为moment objects,然后将它们分配给eventDataTransform中的事件对象的开始/结束参数。祝你好运!

答案 1 :(得分:0)

最后我对它进行了排序。

首先,我创建一个存储库类并添加以下函数。

 public function GetBookings($fieldId)
{
    $sql = "SELECT b.id, b.start_time as start, b.end_time as end, CONCAT( c.first_name,', ', c.last_name) AS title FROM bookings b  LEFT JOIN clients c on b.client_id = c.id WHERE b.field_id=:fieldId ";
    $params = array(
        ':fieldId'=>$fieldId
    );

    return $this->getEntityManager()->getConnection()->executeQuery($sql, $params)->fetchAll();

}

然后更改我的控制器

/**
 * @Route("/get-booking-to-calendar/{id}", name="booking-to-calendar")
 */
public function BookingCalendarAction($id)
{
    $em=$this->getDoctrine()->getManager();

    $bookings= $em->getRepository('AppBundle:Booking')->GetBookings($id);
    $response = new Response(json_encode($bookings));
    $response->headers->set('Content-Type', 'application/json');
    return $response;

}