我使用CodeIgniter的日历库来填充数据库表中的数据,但显然它有以下问题:
为什么会发生这种情况?
型号:
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> • {content} {/cal_cell_content}
{cal_cell_content_today}
<div class="today"><span class="day_listing">{day}</span>• {content}</div>{/cal_cell_content_today}
{cal_cell_no_content}
<span class="day_listing">{day}</span> {/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; ?>
答案 0 :(得分: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()
有关