【发布时间】:2016-11-27 04:10:54
【问题描述】:
我创建了一个方法,它使用日历表编写一个视图,该表使用日历类显示一年中的所有月份。
控制器:
<?php
class Calendar extends CI_Controller {
public function this_year() {
$data['title'] = 'Calendar: ' . date('Y');
$this->load->library('calendar');
$prefs = array(
'local_time' => 'none',
'start_day' => 'sunday',
'month_type' => 'long',
'day_type' => 'short',
'show_next_prev' => FALSE,
'show_other_days' => TRUE,
'template' => '
{table_open}<table class="table table-condensed">{/table_open}
{heading_row_start}<tr class="info">{/heading_row_start}
{cal_cell_start_today}<td class="today">{/cal_cell_start_today}
{cal_cell_start_other}<td class="other-day">{/cal_cell_start_other}
'
);
$this->load->library('calendar', $prefs);
$data['calendar'] = '<table class="table-calendar"><tr>';
for ($i = 1; $i <= 12; $i++) {
if ($i % 3 == 0) {
$data['calendar'].= "<td>{$this->calendar->generate(date('Y'), $i)}</td>";
$data['calendar'].= '</tr><tr>';
}
else {
$data['calendar'].= "<td>{$this->calendar->generate(date('Y'), $i)}</td>";
}
}
$data['calendar'].= '</tr></table>';
$this->template->load('template/index', __CLASS__ . "/" . __FUNCTION__, $data);
}
}
*在查看时,只需回显“$日历”
它也能正常工作,并返回this。
但我没有找到使用日历类中的模板仅突出显示当前月份的方法。我尝试修改默认模板但它不起作用,因为当我更改{heading_title_cell}<th colspan="{colspan}">{heading}</th>{/heading_title_cell} 的类时,它会修改所有月份的标签,如this。
我正在使用基础课程教程中的默认方法(相同的代码)。有什么建议吗?
【问题讨论】:
-
添加一些代码...您可能需要做一些 PHP 来添加条件类:例如一月:
<?php if(date('n') == 1){ $cssClass = 'active'; } ?>,然后将样式应用于.heading_row_start.active -
嘿@reinder,感谢您的关注。我添加了我的控制器源代码。我在想,要做这样的事情,我需要修改 CodeIgniter 的核心。我更喜欢在应用程序上下文中使用本机方法或使用我自己的代码扩展本机类/方法。有什么意见可以帮忙吗? :)
标签: php css codeigniter calendar