I am using CakePHP 3.1 and I can get the events to show on the calendar if they are hard coded. I can also get the events by pasting the array into jsbin and then using the url to get the js file from jsbin as explained in the full calendar docs here and then using the JSON Feed Template link for standard FullCalendar. I need to be able to use the feed url to grab the events so that the events are dynamically added.
You can see my json feed array here. You can see the displayed object in console here.
Feed Method in controller:
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[] = array(
'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('json', json_encode($json, JSON_HEX_QUOT | JSON_HEX_TAG));
$this->set('_serialize', ['json']);
}
Rendering Full Calendar from ready.js file:
jQuery(document).ready(function ($) {
// page is now ready, initialize the calendar...
$('#calendar').fullCalendar({
header: {
left: 'title',
center: '',
right: 'today agendaDay,agendaWeek,month prev,next'
},
defaultView: 'month',
fixedWeekCount: false,
scrollTime: "08:00:00",
aspectRatio: 2,
editable: adminEdit,
events: {
url: 'https://www.utahreia.org/events/feed', //navigate to this url to see json feed array
type: 'POST',
success: function (data) {
console.log(data);
},
error: function (data) {
console.log(data);
}
},
eventRender: function (event, element) {
element.qtip({
content: event.details,
position: {
target: 'mouse',
adjust: {
x: 10,
y: -5
}
},
style: {
name: 'light',
tip: 'leftTop'
}
});
}
})
});
{json: /* your data array*/}
- charlietfljson
property. Just send the json_encode - charlietflset
and are nesting the data and serializing it as well. Just send the array - charlietfl