Im trying to get database data events to load in to me fullcalendar but im not really succeeding. Been trying for many hours now but i dont know why it cant find it. I've been var_dump the data and it is working from the database. I basically have problem to get it into the calendar.
Controller function:
public function getEvents($start, $end)
{
$calendar_model = new \App\Models\CalendarModel();
$event_data = $calendar_model->get_events();
foreach ($event_data as $row) {
$data = [
'ID' => $row->ID,
'description' => $row->description,
'title' => $row->$title,
'start' => $row->start,
'end' => $row->end,
];
}
return json_encode($data);
}
calendar function:
document.addEventListener('DOMContentLoaded', function() {
var calendarEl = document.getElementById('calendar');
var calendar = new FullCalendar.Calendar(calendarEl, {
eventSources: [
{
timeZone: 'UTC',
events: function(start, end, timezone, callback) {
var start = moment('2021-01-10T00:00:00').unix();
var end = moment('2021-01-15T00:00:00').unix();
$.ajax({
url: '<?php echo base_url() ?>/CalenderController/getEvents',
dataType: 'json',
data: {
// our hypothetical feed requires UNIX timestamps
start: start,
end: end
},
success: function(msg) {
var events = msg.events;
callback(events);
}
});
}
},
],
initialView: 'dayGridMonth'
});
// console.log(eventSources);
calendar.render();
})
Ive been trying many types of date types to see if any is working but I cant get it to work..
and here is a picture of my response in log: img of response
It is supposed to show event start date from 2021-01-10 to 2021-01-15
Try changing the return method in Codeigniter 4
return json_encode($data);
From to.
return $this->response->setJSON($data, true);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.