CakePHP与FullCalendar-事件JSON奇怪的问题

时间:2019-05-23 18:03:25

标签: javascript json ajax cakephp fullcalendar

我有CakePHP 3.5.14。来自FullCalendar v3。我将脚本移至另一台服务器。日历已停止工作。我完全动了。

将文件上传到全日历服务器后,它不起作用。从URL导入后,日历才开始显示。日历为空。如果我直接从json给他数据,它将起作用。从url导入无效。我问托管服务提供商-他回答说他们什么也没阻止。

当前文件:

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脚本问题:

>$(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); > } > }); > >}); >

> $(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' > } > ] > }); > });

FullCalendar脚本有效:


> [
>    {
>        "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.json看起来像这样:


> 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');

>   }

进纸方式:

{{1}}

我试图通过PHP对变量进行编码,然后在日历脚本中将其更改为json。不工作。请帮忙。我想念主意。

0 个答案:

没有答案