CakePHP with FullCalendar - events json strange problem

I have CakePHP 3.5.14. from FullCalendar v3. I moved the script to another server. The calendar has stopped working. I moved exactly.

When files were uploaded to the fullcalendar server it did not work. Calendar began to display only after importing from the URL. The calendar is empty. If I give him data directly from json it works. Import from url does not work. I asked the hosting provider - he replied that they are blocking nothing.

Current files:

Html->script('https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js'); ?>

Html->script('https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.1/moment.min.js');?>

Html->script('https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.1.0/fullcalendar.min.js'); ?>

FullCalendar Script problem:

>$(document).ready(function() {
>   $('#calendar').fullCalendar({
>       header: {
>       left: 'prev,next today',
>       center: 'title',
>       right: 'month,agendaWeek,agendaDay,listWeek'
>   },
>       locale: 'pl',
>     
>       defaultDate: '2019-04-12',
>       editable: true,
>       navLinks: true, // can click day/week names to navigate views
>       eventLimit: true, // allow "more" link when too many events
>       events: {
>           url: '/events/feed.json',
>       error: function() {
>               $('#script-warning').show();
>           }
>       },
>       loading: function(bool) {
>           $('#loading').toggle(bool);
>       }
>   });
>
>});


> 

FullCalendar Script it works:

> $(document).ready(function() {

>   $('#calendar').fullCalendar({
>       header: {
>       left: 'prev,next today',
>       center: 'title',
>       right: 'month,agendaWeek,agendaDay,listWeek'
>   },
>       locale: 'pl',
>     
>       defaultDate: '2019-04-12',
>       editable: true,
>       navLinks: true, // can click day/week names to navigate views
>       eventLimit: true, // allow "more" link when too many events
>       events: [
>           {
>           title: 'All Day Event',
>           start: '2019-01-01'
>       },
>       {
>         title: 'Long Event',
>         start: '2019-01-07',
>         end: '2019-01-10'
>        },
>        {
>          id: 999,
>          title: 'Repeating Event',
>          start: '2019-01-09T16:00:00'
>        }

>      ]
>    });

>  });

My feed.json looks like this:

> [
>    {
>        "id": 1,
>        "title": "ccc",
>        "start": null,
>        "end": null,
>        "allDay": false,
>        "url": "\/events\/view\/1",
>        "details": "cccc",
>        "className": "Red"
>    },
>   {
>        "id": 4,
>        "title": "naprawa testowa",
>        "start": "2019-04-26T00:00:00+00:00",
>        "end": "2019-04-26T00:00:00+00:00",
>        "allDay": false,
>        "url": "\/events\/view\/4",
>        "details": "testowa",
>       "className": "Red"
>    }
> ]

Feed method:

> public function feed($id=null) {
>       $this->viewBuilder()->layout('ajax');
>        $vars = $this->request->query([]);
>       $conditions = ['UNIX_TIMESTAMP(start) >=' => $vars['start'], 'UNIX_TIMESTAMP(start)  $vars['end']];
>        $events = $this->Events->find('all', $conditions)->contain(['EventTypes']);

>       foreach($events as $event) {
>            if($event->all_day === 1) {
>                $allday = true;
>                $end = $event->start;
>            } else {
>                $allday = false;
>                $end = $event->end;
>           }
>           
>            $json[] = [
>                    'id' => $event->id,
>                   'title' => $event->title,
>                    'start'=> $event->start,
>                    'end' => $end,
>                    'allDay' => $allday,
>                   'url' => Router::url(['action' => 'view', $event->id]),
>                    'details' => $event->details,
>                    'className' => $event->event_type->color
>            ];
>       }

>   $this->set(compact('json'));
>   $this->set('_serialize', 'json');

>   }

I tried to encode the variable through PHP and change it to json in calendar script. Did not work. Please help. I miss ideas.

You can debug this using the Javascript console in your browser so see if there are any errors.
You can also use your browsers network monitor to see the response from the server :slight_smile:

Since my last message in this tread was flagged as unwanted…

Adam89 can you please pm me description of your problem, feel free to use Polish as English description doesn’t tells me much about your issues.

Your message was flagged as unwanted since it was not in English :slight_smile:
We like comments to be in English because then it can be helpful for some other soul that comes by a similar issue.

1 Like