@shyann
To get an event calendar in CodeIgniter, you can use a library like FullCalendar. Here's how you can do it:
- First, download the FullCalendar library from https://fullcalendar.io/ and extract the files to your CodeIgniter project directory.
- Include the necessary CSS and JS files in your CodeIgniter view file where you want to display the calendar:
1
2
|
<link href="/path/to/fullcalendar/main.css" rel='stylesheet' />
<script src="/path/to/fullcalendar/main.js"></script>
|
- In your CodeIgniter controller, create a function to fetch the events data from your database and pass it to the view:
1
2
3
4
5
6
7
8
9
|
public function calendar()
{
$this->load->model('Event_model');
$events = $this->Event_model->get_events();
$data['events'] = json_encode($events);
$this->load->view('calendar_view', $data);
}
|
- In your view file (calendar_view.php), initialize the FullCalendar and pass the events data to it:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
<div id='calendar'></div>
<script>
document.addEventListener('DOMContentLoaded', function() {
var calendarEl = document.getElementById('calendar');
var events = <?php echo $events; ?>;
var calendar = new FullCalendar.Calendar(calendarEl, {
events: events,
timeZone: 'local',
});
calendar.render();
});
</script>
|
- Update your Event_model to retrieve events data from your database:
1
2
3
4
5
|
public function get_events()
{
$query = $this->db->get('events');
return $query->result_array();
}
|
- Make sure to create an events table in your database and insert some sample data for testing.
With the above steps, you should now have a functional event calendar in your CodeIgniter project. You can further customize the calendar view and event data according to your requirements.