2016-06-17 9 views
1

私はsymfonyでフルカレンダーを使用しています。しかし、イベントはレンダリングされていません。私はいたるところで試しました。fullcalendarはイベントを表示しません

コントローラコード

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


} 

小枝

<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が

click to view image

+0

私のコントローラを変更します。それはどこで失敗しますか?私はそれのコードが表示されません。 –

+0

eventRender関数は何に関係なく 'event.allDay'をtrueに設定します。それは意図的なのでしょうか? –

+0

また、カレンダーdivのレンダリングされたhtmlを投稿できますか? –

答えて

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

} 

その後、上記のコードはOKに見える

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

} 
0

をレンダリングであるあなたがeventDataTransformフックを使用してみましたか?イベントオブジェクトを手動で取り込み、まだ問題が発生していないかどうかを確認してください。 Fullcalは私の開始/終了ISO8901を正しく解析していなかったので、私は同じ問題を抱えていました。 eventDataTransformのイベントオブジェクトの開始/終了パラメータにJSON開始/終了データを代入する前に、moment objectsにJSON開始/終了データをパースしなければなりませんでした。運が良かった!

+0

私はその方法を試みたが、まだイベントをレンダリングしていない – mehmet

関連する問題