1

我使用 CodeIgniter 的日历库从数据库表中填充数据,但显然它存在以下问题:

  • 显示的记录不超过 1 个
  • 当其他一切正常时,不显示该月第 9 天以下的条目

为什么会发生这种情况?

模型:

class reminders_model extends CI_Model {

var $conf;

function reminders_model() {
    parent::__construct(); 
    $this->conf = array(
        'start_day' => 'monday',
        'month_type' => 'long',
        'day_type' => 'long'
        );
    $this->conf['template'] = '
        {table_open}
            <table class="calendar">
        {/table_open}

        {week_day_cell}
            <th class="day_header">{week_day}</th>
        {/week_day_cell}

        {cal_row_start}<tr class="days">{/cal_row_start}
        {cal_cell_start}<td class="day">{/cal_cell_start}

        {cal_cell_content}
            <span class="day_listing">{day}</span>&nbsp;&bull; {content}&nbsp;{/cal_cell_content}
        {cal_cell_content_today}
            <div class="today"><span class="day_listing">{day}</span>&bull; {content}</div>{/cal_cell_content_today}
        {cal_cell_no_content}
            <span class="day_listing">{day}</span>&nbsp;{/cal_cell_no_content}
        {cal_cell_no_content_today}
            <div class="today"><span class="day_listing">{day}</span></div>{/cal_cell_no_content_today}
        ';
}

function get_calendar_data($year, $month) {
    $query = $this->db->select('date, reason')->from('reminders')->like('date', "$year-$month", 'after')->get();

    $cal_data = array();

    foreach ($query->result() as $row) {
        $cal_data[substr($row->date, 8, 2)] = $row->reason;
    }

    return $cal_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);

}

控制器:

<?php

class reminders extends CI_Controller {

function index($year = null, $month = null) {

    if (!$year) {
        $year = date('Y');
    }
    if (!$month) {
        $month = date('m');
    }

    $this->load->model('/summary/reminders_model');

    if ($day = $this->input->post('day')) {
        $this->reminders_model->add_calendar_data(
            "$year-$month-$day", 
            $this->input->post('reason')
            );
    }

    $data['calendar'] = $this->reminders_model->generate($year, $month);
    $this->load->view('summary/reminders_view', $data);
}

看法:

<?php echo $calendar; ?>
4

1 回答 1

0

为了在一天中放入多个项目,比如说 15 日,您必须创建一个多维数组来获取多个约会。例如。

function get_calendar_data($year, $month) {
    $query = $this->db->select('date, reason')->from('reminders')->like('date', "$year-$month", 'after')->get();

    $cal_data = array();

    foreach ($query->result() as $row) {
        $day = date('j',$row->date);
        $cal_data[$day][] = $row->reason;
    }

    return $cal_data;
}

至于你只得到 9 的原因,我猜这与你的 substr()

于 2013-07-15T22:30:23.060 回答