2016-11-26 66 views
0

我做了一个方法,写一个日历表的方法,该日历表使用日历类显示一年的所有月份。日历自定义[突出显示当前月份]

控制器:

<?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

我使用基本类教程中的默认方法(相同的代码)。任何建议?

+0

添加一些代码...你可能需要做一些PHP添加有条件类:例如对于一月:'<?php if(date('n')== 1){$ cssClass ='active'; }?>' 然后将样式应用到'.heading_row_start.active' – reinder

+0

嘿@reinder,感谢您的关注。我添加了我的控制器源代码。我在想,要做这样的事情,我需要修改CodeIgniter的核心。我更喜欢使用本地方法或使用自己的代码在应用程序上下文中扩展本地类/方法。任何意见帮助? :) – ShutUpMagda

回答

0

有可能extendCI_Calendar强制方法generate()将他的$month变量传递给parse_template()方法。然后,parse_template($month)将能够应用例外在解析上{heading_row_start}<tr>{/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]; 
} 
相关问题