0

下面的代码是来自这里的 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}">&lt;&lt;</a></th>{/heading_previous_cell}
            {heading_title_cell}<th colspan="{colspan}">{heading}</th>{/heading_title_cell}
            {heading_next_cell}<th><a href="{next_url}">&gt;&gt;</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}&nbsp;{/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>
4

3 回答 3

0

问题在于您在事件中传递的日期格式。请注意

$data= array('day'=>01,'day_data'=>'abcd');

不一样

$data= array('day'=>1,'day_data'=>'abcd');

因此所有日期低于 1​​0 的问题。更新您的代码以保持统一的日期格式

于 2021-09-15T08:45:00.613 回答
0

这是上述问题的确切解决方案。

if($this->uri->segment(3)){

   $year=$this->uri->segment(3);

} 别的{

 $年=日期(“Y”);

}

if($this->uri->segment(4)){

   $month=$this->uri->segment(4);

} 别的{

 $月=日期("m");

}

$数据=数组(

    '年'=>$年,

    '月'=>$月

);

$prefs = 数组(

        'month_type' => 'long',

        'day_type' => '短',

        'show_next_prev' => 真,

        'next_prev_url' => base_url().'欢迎/新闻/'

);

$prefs['模板'] = '

   {table_open}table{border-collapse:collapse; 颜色:#f6f6f6;} td{ 宽度:40px; 高度:40px;文本对齐:居中;边框:1px 实心#e2e0e0;字体大小:18px;字体粗细:粗体;} th{ 高度:68px; 底部填充:12px;文本对齐:居中;字体大小:20px;} .prev_sign a, .next_sign a{ 颜色:白色;文字装饰:无;} tr.week_name{ 字体大小:16px; 字体粗细:400;红色; 宽度:10px;背景颜色:#efe8e8;} .highlight{背景颜色:#25BAE4; 颜色:#e6f0e9; 高度:39px;padding-top: 7px;}{/table_open}

        {heading_row_start}{/heading_row_start}

        {heading_previous_cell}<<{/heading_previous_cell}

        {heading_title_cell}{heading}{/heading_title_cell}

        {heading_next_cell}>>{/heading_next_cell}

        {heading_row_end}{/heading_row_end}

        {week_row_start}{/week_row_start}

        {week_day_cell}{week_day}{/week_day_cell}

        {week_row_end}{/week_row_end}

        {cal_row_start}{/cal_row_start}

        {cal_cell_start}{/cal_cell_start}

        {cal_cell_start_today}{/cal_cell_start_today}

        {cal_cell_start_other}{/cal_cell_start_other}

        {cal_cell_content}{day}{/cal_cell_content}

        {cal_cell_content_today}{day}{/cal_cell_content_today}

        {cal_cell_no_content}{day}{/cal_cell_no_content}

        {cal_cell_no_content_today}{day}{/cal_cell_no_content_today}

        {cal_cell_blank} {/cal_cell_blank}

        {cal_cell_other}{day}{/cal_cel_other}

        {cal_cell_end}{/cal_cell_end}

        {cal_cell_end_today}{/cal_cell_end_today}

        {cal_cell_end_other}{/cal_cell_end_other}

        {cal_row_end}{/cal_row_end}

        {table_close}{/table_close}

';

   $this->load->library('日历',$prefs);

 $data2=$data1=数组();

        

        foreach($event as $d) {

                $date=date_create($d['date']);

                $date_f= date_format($date,"Y/m/d");

                $y=date_format($date,"Y");

                $m=date_format($date,"m");

                $d1=strval(intval(date_format($date,"d")));

                if($y==$year && $m==$month){

                        $data1[$d1] = base_url().'welcome/alleventbydate/'.$date_f;

                }

        }

        //$data[]=$data1;

      

        echo $this->calendar->generate($year,$month,$data1);

于 2018-04-11T15:01:52.417 回答
-2

这是上述问题的确切解决方案。按照此编码,您将获得解决方案。请根据您的要求修改代码。

if($this->uri->segment(3)){

   $year=$this->uri->segment(3);

} else{


 $year=date("Y");

}


if($this->uri->segment(4)){

   $month=$this->uri->segment(4);

} else{


 $month=date("m");

}

$data=array(


    'year'=>$year,

    'month'=>$month

);


$prefs = array(


        'month_type'   => 'long',

        'day_type'     => 'short',


        'show_next_prev'  => TRUE,

        'next_prev_url'   => base_url().'welcome/news/'

);


$prefs['template'] = '

   {table_open}<style>table{border-collapse:collapse; color: #f6f6f6;} td{ width: 40px; height: 40px; text-align: center; border: 1px solid #e2e0e0; font-size: 18px; font-weight: bold; } th{ height: 68px; padding-bottom: 12px; text-align: center; font-size: 20px; } .prev_sign a, .next_sign a{ color:white; text-decoration: none; } tr.week_name{ font-size: 16px; font-weight:400; color:red; width: 10px; background-color: #efe8e8; } .highlight{background-color: #25BAE4; color:#e6f0e9; height: 39px; padding-top: 7px;}</style><table class="col-lg-12 col-md-12 col-sm-12 col-xs-12" border="0" cellpadding="0" cellspacing="0">{/table_open}


        {heading_row_start}<tr>{/heading_row_start}


        {heading_previous_cell}<th><a href="{previous_url}">&lt;&lt;</a></th>{/heading_previous_cell}

        {heading_title_cell}<th colspan="{colspan}">{heading}</th>{/heading_title_cell}

        {heading_next_cell}<th><a href="{next_url}">&gt;&gt;</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>{/cal_row_start}

        {cal_cell_start}<td>{/cal_cell_start}

        {cal_cell_start_today}<td>{/cal_cell_start_today}

        {cal_cell_start_other}<td class="other-month">{/cal_cell_start_other}


        {cal_cell_content}<a href="{content}">{day}</a>{/cal_cell_content}

        {cal_cell_content_today}<div class="highlight"><a href="{content}">{day}</a></div>{/cal_cell_content_today}


        {cal_cell_no_content}{day}{/cal_cell_no_content}

        {cal_cell_no_content_today}<div class="highlight">{day}</div>{/cal_cell_no_content_today}


        {cal_cell_blank}&nbsp;{/cal_cell_blank}


        {cal_cell_other}{day}{/cal_cel_other}


        {cal_cell_end}</td>{/cal_cell_end}

        {cal_cell_end_today}</td>{/cal_cell_end_today}

        {cal_cell_end_other}</td>{/cal_cell_end_other}

        {cal_row_end}</tr>{/cal_row_end}


        {table_close}</table>{/table_close}

';


   $this->load->library('calendar',$prefs);








 $data2=$data1=array();

        

        foreach($event as $d) {

                $date=date_create($d['date']);

                $date_f= date_format($date,"Y/m/d");

                $y=date_format($date,"Y");

                $m=date_format($date,"m");

                $d1= strval(intval(date_format($date,"d")));

                if($y==$year && $m==$month){

                        $data1[$d1]  = base_url().'welcome/alleventbydate/'.$date_f;

                }

        }

        //$data[]=$data1;

      

        echo $this->calendar->generate($year,$month,$data1);
于 2018-04-11T14:48:05.767 回答