如何使用codeiginater在日历中显示事件



我已经显示了日历,下面的代码是

<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<link href='https://fullcalendar.io/releases/fullcalendar/3.9.0/fullcalendar.min.css' rel='stylesheet' />
<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/
bootstrap.min.css'>
<link href='https://fullcalendar.io/releases/fullcalendar/3.9.0/fullcalendar.print.min.css' rel='stylesheet' media='print' />
<script src='https://fullcalendar.io/releases/fullcalendar/3.9.0/lib/moment.min.js'></script>
<script src='https://fullcalendar.io/releases/fullcalendar/3.9.0/lib/jquery.min.js'></script>
<script src='https://fullcalendar.io/releases/fullcalendar/3.9.0/fullcalendar.min.js'></script>
<script src='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min
.js'></script>
<script>
$(document).ready(function() {
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month'
},
defaultDate: new Date(),
navLinks: true, // can click day/week names to navigate views
editable: true,
eventLimit: true,
droppable: true,  // allow "more" link when too many events
dayClick: function(date, jsEvent, view) {
$("#successModal").modal("show");
$("#eventDate").val(date.format());
},
events: <?php echo json_encode($myArray); ?>   });
});
</script>
<style>
body {
margin: 40px 10px;
padding: 0;
font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
font-size: 14px;
}
#calendar {
max-width: 900px;
margin: 0 auto;
}
</style>
</head>
<body>
<div id='calendar'></div>
<div class="modal fade" id="successModal" role="dialog" aria-labelledby="successModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">Apply Leave</h4>
</div>
<div class="modal-body">
<form action="#" method="post">
<div class="form-group">
<label for="eventtitle">Event Title:</label>
<input type="text" name="eventTitle" class="form-control" id="eventTitle" required="" value="Leave">
<!--      <input type="color" name="eventColor" class="form-control" id="eventColor" required="">-->
<input type="hidden" name="eventDate" class="form-control" id="eventDate">
</div>
<button type="submit" value="submit" name="submit" class="btn btn-default">Apply Leave</button>
</form>
</div>
</div>
</div>
</div>
</body>
</html>

这是查看页面代码。在这个页面中,当点击日期时,它会弹出,我点击应用休假按钮,数据会存储在数据库中。但当数据保存到数据库中时,它不会显示在日历的首页。

我的控制器代码

public function index()
{
if(isset($_POST["submit"]) == "submit" && isset($_POST["eventTitle"]) != "")
{
$da=array(
'title' => $this->input->post('eventTitle'),
'event_date'=> $this->input->post('eventDate'),
);
$sql = $this->db->insert('events',$da);
if ($sql) {
echo "New event added successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
$sql['row'] = $this->db->query("SELECT title, event_date as start, backgroundColor FROM events")->row_array();
if ($sql->num_rows > 0) {
// output data of each row
while($row = $sql->fetch_assoc()) {
$myArray[] = $row;
}
} 
else 
{
echo "0 results";
}
$this->load->view('Leave');
}

它只显示"0"值和一些错误

将查询更改为此代码希望这有帮助

$sql = $this->db->select('title, event_date as start, backgroundColor')->get('events');
if ($sql->num_rows > 0) {   
foreach($sql->row_array() as $row){
$myArray[] = $row;    
}

相关内容

  • 没有找到相关文章

最新更新