下面的代码是来自这里的 Codeigniter 事件日历功能。
日历是可点击的,您可以通过“提示”框在日期字段中输入数据。然后数据将显示在日历日期字段中。
除了每个月的前 10 天左右,日历事件功能在所有日期都按预期工作。这些特定日期(即前 10 天的日期)的数据存储在数据库中,但数据不会显示在日历上。
我不确定为什么会发生这种情况,而本月的其余日期都运行良好。有人可以帮忙吗?
//CONTROLLER
class Mycal extends CI_Controller {
public function index() {
$this->display();
}
function display($year = null, $month = null){
if (!$year) {
$year = date('Y');
}
if (!$month) {
$month = date('m');
}
$this->load->model('Mycal_model');
if($day = $this->input->post('day')){
$this->Mycal_model->add_calendar_data(
"$year-$month-$day",
$this->input->post('data')
);
}
$data['calendar'] = $this->Mycal_model->generate($year, $month);
$this->load->view('mycal_view', $data);
}
}
//MODEL
class Mycal_model extends CI_Model{
var $conf;
function __construct(){
parent::__construct();
$this->conf = array(
'start_day' => 'monday',
'show_next_prev' => true,
'next_prev_url' => base_url() . 'index.php/mycal/display'
);
$this->conf['template'] = '
{table_open}<table border="0" cellpadding="0" cellspacing="0" class="calendar">{/table_open}
{heading_row_start}<tr>{/heading_row_start}
{heading_previous_cell}<th><a href="{previous_url}"><<</a></th>{/heading_previous_cell}
{heading_title_cell}<th colspan="{colspan}">{heading}</th>{/heading_title_cell}
{heading_next_cell}<th><a href="{next_url}">>></a></th>{/heading_next_cell}
{heading_row_end}</tr>{/heading_row_end}
{week_row_start}<tr>{/week_row_start}
{week_day_cell}<td>{week_day}</td>{/week_day_cell}
{week_row_end}</tr>{/week_row_end}
{cal_row_start}<tr class="days">{/cal_row_start}
{cal_cell_start}<td class="day">{/cal_cell_start}
{cal_cell_content}
<div class="day_num">{day}</div>
<div class="content">{content}</div>
{/cal_cell_content}
{cal_cell_content_today}
<div class="day_num highlight">{day}</div>
<div class="content">{content}</div>
{/cal_cell_content_today}
{cal_cell_no_content}<div class="day_num">{day}</div>{/cal_cell_no_content}
{cal_cell_no_content_today}<div class="day_num highlight">{day}</div>{/cal_cell_no_content_today}
{cal_cell_blank} {/cal_cell_blank}
{cal_cell_end}</td>{/cal_cell_end}
{cal_row_end}</tr>{/cal_row_end}
{table_close}</table>{/table_close}
';
}
function get_calendar_data($year, $month){
$query = $this->db->select('date, data')->from('calendar')
->like('date', "$year-$month", 'after')->get();
$cal_data = array();
foreach ($query->result() as $row){
$cal_data[substr($row->date,8,2)] = $row->data;
}
return $cal_data;
}
function add_calendar_data($date, $data){
if($this->db->select('date')->from('calendar')
->where('date', $date)->count_all_results()) {
$this->db->where('date', $date)->update('calendar', array(
'date'=>$date,
'data'=>$data
));
}else{
$this->db->insert('calendar', array(
'date'=>$date,
'data'=>$data
));
}
}
function generate ($year, $month){
$this->load->library('calendar', $this->conf);
$cal_data = $this->get_calendar_data($year, $month);
return $this->calendar->generate($year, $month, $cal_data)
}
//VIEW
<?php echo $calendar; ?>
<script type="text/javascript">
$(document).ready(function() {
$('.calendar .day').click(function() {
day_num = $(this).find('.day_num').html();
day_data = prompt('Enter Stuff', $(this).find('.content').html());
if(day_data !=null){
$.ajax({
url: window.location,
type: 'POST',
data: {
day: day_num,
data: day_data
},
success: function(msg){
location.reload();
}
});
}
});
});
</script>