Today, We will learn how to integrate the full calendar library in Codeigniter 3. Follow few steps to create an event, select a time slot, etc, and save it into the database.
Step 1:
Create events database table
CREATE TABLE IF NOT EXISTS `events` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(255) NOT NULL,
`start_date` date NOT NULL,
`end_date` date NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;
Step 2:
adjust database configuration application/config/database.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
$active_group = 'default';
$query_builder = TRUE;
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => 'root',
'database' => 'test',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
Step 3:
Make Route application/config/routes.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
$route['my-calendar'] = "CaledarController";
Step 4:
Create Controllerapplication/controllers/CaledarController.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class CaledarController extends CI_Controller {
/**
* Get All Data from this method.
*
* @return Response
*/
public function __construct() {
parent::__construct();
$this->load->database();
}
/**
* Get All Data from this method.
*
* @return Response
*/
public function index()
{
$data['result'] = $this->db->get("events")->result();
foreach ($data['result'] as $key => $value) {
$data['data'][$key]['title'] = $value->title;
$data['data'][$key]['start'] = $value->start_date;
$data['data'][$key]['end'] = $value->end_date;
$data['data'][$key]['backgroundColor'] = "#00a65a";
}
$this->load->view('my_calendar', $data);
}
}
Step 5:
Create view application/views/my_calendar.php
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.9.0/fullcalendar.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.9.0/fullcalendar.min.js"></script>
</head>
<body>
<div class="container">
<div class="row" style="width:50%">
<div class="col-md-12">
<div id="calendar"></div>
</div>
</div>
</div>
<script type="text/javascript">
var events = <?php echo json_encode($data) ?>;
var date = new Date()
var d = date.getDate(),
m = date.getMonth(),
y = date.getFullYear()
$('#calendar').fullCalendar({
header : {
left : 'prev,next today',
center: 'title',
right : 'month,agendaWeek,agendaDay'
},
buttonText: {
today: 'today',
month: 'month',
week : 'week',
day : 'day'
},
events : events
})
</script>
</body>
</html>
finally, Run your application
http://localhost/your_ci_project/my-calendar |
Thanks, I hope it will work for you.....