dimanche 19 juin 2016

fullcalendar not rendering the event

I am using full calendar with symfony. However the events not been rendered. I tried every way.

Controller Code

  /**
 * @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>

and my json respond is

[{"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}]

it seems eveything is ok. but the events are not coming on the calendar.

here is html render

click to view image

Aucun commentaire:

Enregistrer un commentaire