我不知道如何更新或刪除我的symfony項目上的fullcalendar事件。如何使用Symfony更新或刪除fullCalendar事件
要添加新事件,我打開一個窗體的模態窗口提交新事件並將其插入到我的數據庫中。
這是我CONTROLER(它工作正常):
$datas = array();
$form = $this->createFormBuilder($datas)
->add('title', TextType::class)
->add('startDate', TextType::class, array(
'attr'=> array('class' => 'dateTimePicker')))
->add('endDate', TextType::class, array(
'attr'=> array('class' => 'dateTimePicker')))
->add('backgroundColor', ChoiceType::class, array('choices' => $color))
->getForm();
$form->handleRequest($request);
/** Création d'un nouvel évenement */
if ($form->isSubmitted() && $form->isValid()) {
$title = $form->get('title')->getData();
$start = new \DateTime($form->get('startDate')->getData());
$end = new \DateTime($form->get('endDate')->getData());
$backgroundColor = $form->get('backgroundColor')->getData();
$event = new CalendarEvent();
$event->setTitle($title);
$event->setStartDate($start);
$event->setEndDate($end);
$event->setBackgroundColor($backgroundColor);
$em = $this->getDoctrine()->getManager();
$em->persist($event);
$em->flush();
return $this->redirect($this->generateUrl('ma_lrm_accueil'));
}
我知道,更新的事件,我必須有這樣一個javascript:
$(document).ready(function() {
$('#calendar').fullCalendar({
header: {
left: 'prev, next',
center: 'title',
right: 'month, agendaWeek, agendaDay'
},
timezone: ('Europe/London'),
businessHours: {
start: '09:00',
end: '18:30',
dow: [1, 2, 3, 4, 5]
},
allDaySlot: true,
defaultView: 'agendaWeek',
lazyFetching: true,
firstDay: 1,
selectable: true,
/*timeFormat: {
agenda: 'h:mmt',
'': 'h:mmt'
},*/
editable: true,
eventDurationEditable: true,
events: 'http://localhost/ligne_rh/web/app_dev.php/admin/accueil/calendar',
eventResize: function(events) {
console.log("Entrée dans : eventResize");
var start1 = events.start.format('Y-m-d\TH:i:s');
var end1 = events.end.format('Y-m-d\TH:i:s');
var xhr = $.ajax({
type: "POST",
url: 'http://localhost/.../calendar/event/update',
data: 'title=' + events.title + '&start=' + start1 + '&end=' + end1 + '&id=' + events.id,
dataType: 'html',
success: function(data) {
window.location.reload(true);
},
error: function() {
alert("...");
},
});
},
});
我不明白它的任何我不知道我的控制器應該是什麼樣子。
請幫助我一個例子!我是新手!謝謝!!!!
你真的想要什麼?出現一些錯誤? –
我不知道我的updateAction應該如何?它應該返回JSON和如何?我不明白我的js和我的動作控制器之間的聯繫 – Moh