0

this my function in controller

public function loadcalendarAction() {

    $eventsloaded = $this->container->get('calendarbundle.serviceloadcalendar')->loadCalendar();
    $response = new JsonResponse();
    //dump($eventsloaded);
    //die();
    $response->setData(array('events' => $eventsloaded));
    return $response;
}

the $eventsloaded is an array of 2 events in my database its OK .. but $response is empty i don't know why ..

the response is empty

and this my calendar_setting.js

$(document).ready(function () {
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();

$('#calendar').fullCalendar({
    header: {
        left: 'prev,next today',
        center: 'title',
        right: 'month,agendaWeek,agendaDay'
    },
    defaultDate: '2016-01-12',
    lang: 'ar-tn',
    buttonIcons: false, // show the prev/next text
    weekNumbers: true,
    editable: true,
    eventLimit: true, // allow "more" link when too many events
    dayClick: function () {
        alert('a day has been clicked!');
    },
    events: Routing.generate('loadcalendar')
});
});

if the response not empty all the events will be displayed in the events:

nasri_thamer
  • 109
  • 1
  • 15

1 Answers1

0

Look at this questions' answer. You need either to use some external bundle (such as JMSSerializerBundle) to serialize entity, to pass it to json response, or implement something like toArray() method in your entity which will return an array of needed data from entity, after that you could do smth like:

$responseData = [];
foreach ($eventsloaded as $i => $event) {
    $responseData[$i] = $event->toArray();
}

return new JsonResponse($responseData);
Community
  • 1
  • 1
Ilya Yarkovets
  • 820
  • 4
  • 12
  • thank you so much it works .. but it returns to me like this [{"id":1,"title":"event 1","start_time":"2016-01-28T09:00:00+0100","end_time":"2016-01-31T09:00:00+0100"},{"id":2,"title":"event 2","start_time":"2016-01-25T12:00:00+0100","end_time":"2016-01-25T16:00:00+0100"}] [{"id":1,"title":"event 1","start_time":"2016-01-28T09:00:00+0100","end_time":"2016-01-31T09:00:00+0100"},{"id":2,"title":"event 2","start_time":"2016-01-25T12:00:00+0100"}] – nasri_thamer Jan 28 '16 at 09:30
  • the answer is the filter raw in twig {{ events|raw }} – nasri_thamer Jan 30 '16 at 07:35