【问题标题】:Calendaring customization [highlighting the current month]日历自定义[突出显示当月]
【发布时间】: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}&lt;th colspan="{colspan}"&gt;{heading}&lt;/th&gt;{/heading_title_cell} 的类时,它会修改所有月份的标签,如this

我正在使用基础课程教程中的默认方法(相同的代码)。有什么建议吗?

【问题讨论】:

  • 添加一些代码...您可能需要做一些 PHP 来添加条件类:例如一月:&lt;?php if(date('n') == 1){ $cssClass = 'active'; } ?&gt;,然后将样式应用于.heading_row_start.active
  • 嘿@reinder,感谢您的关注。我添加了我的控制器源代码。我在想,要做这样的事情,我需要修改 CodeIgniter 的核心。我更喜欢在应用程序上下文中使用本机方法或使用我自己的代码扩展本机类/方法。有什么意见可以帮忙吗? :)

标签: php css codeigniter calendar


【解决方案1】:

extendCI_Calendar 可以强制方法generate() 将他的$month 变量传递给parse_template() 方法。然后,parse_template($month) 将能够在解析 {heading_row_start}&lt;tr&gt;{/heading_row_start} 上声明的模板时应用异常:

CI_Calendar::parse_template($month), 483:

if($val == 'heading_row_start'){
  if( $month == date('m')){
    $this->replacements[$val] = '<tr class="info">';
  }
}
else{
  $this->replacements[$val] = $match[1];
}

【讨论】:

    猜你喜欢
    • 2016-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多