1

I know this question has been asked by many people but I still have not found the answer to solve the problem

TutorsController:

public function index()
{
    $this->loadModel('Events');
        $events = $this->Events->find('all');
        foreach ($events as $event) {
            $data[] = array(
                'id' => $event->id,
                'title' => $event->title,
                'start' => $event->start->format('Y-m-d H:i:s'),
                'end' => $event->end->format('Y-m-d H:i:s'),
            );
        }
        $this->set('json', json_encode($data, JSON_HEX_QUOT | JSON_HEX_TAG));
        $this->set('_serialize', 'data');
}

js file:

$(document).ready(function(){
    var calendar = $('#calendar').fullCalendar({
        header:{
            left: 'prev,next today',
            center: 'title',
            right: 'agendaWeek,agendaDay'
        },
        defaultView: 'agendaWeek',
        editable: true,
        selectable: true,
        allDaySlot: false,
        height : function() {
            return $(window).height()*0.8;
        },
        events: "http://localhost/jp_matching/tutor/tutors",
}

Please help me!

  • What exactly **is** the problem? Server error? Or Ajax error? Or maybe the data just isn't in the right format. What debugging have you done? Please try and narrow down the issue – ADyson Aug 24 '19 at 17:52
  • I think the problem is because the way cakephp displays json data, everything else works properly ( because when I try to export the data it is in json format but not displayed on fullcalendar ) –  Aug 25 '19 at 03:09
  • Ok so please show an example of the JSON being created by cakePhP – ADyson Aug 25 '19 at 08:13
  • An example: [{"id":30,"title":"vvvvv","start":"2019-08-21T18:00:00+00:00","end":"2019-08-21T19:30:00+00:00"}] –  Aug 25 '19 at 09:50
  • I can't test it right now but I wonder if the `+00:00` is the issue. Try formatting the date without that – ADyson Aug 25 '19 at 10:57
  • I also thought it was a problem and tried it before but it still doesn't work –  Aug 25 '19 at 11:10
  • Hm strange. I'm away right now but when I'm back in front of a PC I'll test it out properly – ADyson Aug 25 '19 at 19:20
  • Ok I got back from holiday and checked this out. Using exactly the JSON you mentioned above as static data, there's no issue at all. The event shows up as it should. Demo: http://jsfiddle.net/fs63kwn4/ . Are you sure that fullCalendar is able to download the event data correctly? Have you looked at your Network tools in the browser when loading your page, to see if the event URL is accessed correctly, that the response from that URL contains exactly what you showed, and that there are no other JavaScript errors? – ADyson Aug 28 '19 at 08:00
  • P.S. Here's a demo fetching your sample JSON from a remote URL, and using exactly your calendar setup code above, and it still works correctly: http://jsfiddle.net/fs63kwn4/1/ . If you are getting a different result you'll need to to some much more detailed debugging to determine why. – ADyson Aug 28 '19 at 08:04
  • Thank you so much. I solved the problem by adding .json to the end of the events' url (although I don't really understand why it worked) –  Aug 29 '19 at 03:36
  • Can you help me with this: I want to initially set the editable, selectable, droppable and events to false, when the user clicks a button, retrieves the data successfully, then set them to true. I'm a newbie and I don't know how to handle it with js –  Aug 29 '19 at 03:42
  • Please ask a new question about it. Then we can help you properly – ADyson Aug 29 '19 at 05:54
  • Please help me solve it https://stackoverflow.com/questions/57712687/disable-and-activate-fullcalendar –  Aug 29 '19 at 14:50

0 Answers0