我正在使用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}]
看来还可以。但是这些事件并不是日历上的。
这是html渲染
单击查看图像
您是否尝试过使用EventDatatRansform钩?手动填充事件对象,看看您是否仍在遇到问题。FullCal并未正确解析我的开始/结束ISO8901,我遇到了同样的问题。在将事件对象分配给EventDatatRansform中的事件对象的启动/结束参数之前,我必须将JSON启动/结束数据解析为矩对象。祝您好运!
最后我对其进行排序。
首先,我创建一个存储库类并添加以下函数。
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;
}