1

我正在使用 CI 日历。我与之连接的数据库具有以下列:日期、小时、类别和注释。我从net tuts+开始使用与本教程中相同的格式。我可以让日历在适当的日子显示笔记,但我不确定如何将内容部分分成小时、类别和笔记。我知道我必须修改系统文件中的生成日历,但不知道该怎么做。

这是我的代码:

控制器:

function index($year = null, $month = null)
    {
        if (!$year) {
            $year = date('Y');
        }
        if (!$month) {
            $month = date('m');
        }

        $this->load->model('calendar_model');

        if ($day = $this->input->post('day')) {
            $this->calendar_model->add_calendar_data(
                "$year-$month-$day",
                $this->input->post('hours'),
                $this->input->post('category'),
                $this->input->post('notes')
            );
        }

        $data['calendar'] = $this->calendar_model->generate($year, $month);


        // Load a view in the content partial
        $this->template->content->view('includes/user_navigation');
        $this->template->content->view('dashboard', $data);

        // Display the template
        $this->template->publish();

    }

模型:

<?php

class Calendar_model extends CI_Model {

   var $conf;

     function Calendar_model()
    {
      parent::__construct();


  }

  function get_calendar_data($year, $month) {

    $query = $this->db->select()->from('calendar')
      ->like('date', "$year-$month", 'after')->get();

    $cal_data = array();

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


      /* Testing purposes */
      echo "<p>" . $row->date . "</p>";
      echo"<p>" . $row->hours . "</p>";
      echo "<p>" . $row->category . "</p>";
      echo "<p>" . $row->notes . "</p>";
    }

    return $cal_data;

  }

  function add_calendar_data($date, $hours, $category, $notes) {

    if ($this->db->select('date')->from('calendar')
        ->where('date', $date)->count_all_results()) {

      $this->db->where('date', $date)
        ->update('calendar', array(
        'date' => $date,
        'hours' => $hours,
        'category' => $category,
        'notes' => $notes
      ));

    } else {

      $this->db->insert('calendar', array(
        'date' => $date,
        'hours' => $hours,
        'category' => $category,
        'notes' => $notes
      ));
    }

  }

  function generate ($year, $month) {

    $this->load->library('calendar');

    $cal_data = $this->get_calendar_data($year, $month);

    return $this->calendar->generate($year, $month, $cal_data);

  }
}

日历模板:

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
|--------------------------------------------------------------------------
| Calendar configuration
|--------------------------------------------------------------------------
| This file will contain the settings for the calendar template library.
|
*/

$config['day_type'] = 'long';
$config['show_next_prev'] = true;
$config['next_prev_url'] = base_url('index.php/calendar/display');

$config['template'] = '

      {table_open}
        <table class="calendar">
      {/table_open}

      {heading_row_start}<tr>{/heading_row_start}
      {heading_previous_cell}<th><a href="{previous_url}">&lt;&lt;</a></th>{/heading_previous_cell}
      {heading_title_cell}<th colspan="{colspan}">{heading}</th>{/heading_title_cell}
      {heading_next_cell}<th><a href="{next_url}">&gt;&gt;</a></th>{/heading_next_cell}
      {heading_row_end}</tr>{/heading_row_end}

      {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}
        <div class="day_num">{day}</div>
        <div class="content">
          <div class="category">{category}
            <div class="hours">{hours}
              <div class="notes">{notes}
                {content}
              </div>
            </div>
          </div>
        </div>
      {/cal_cell_content}

      {cal_cell_content_today}
        <div class="today"><div class="day_num">{day}</div>
        <div class="content">{content}</div></div>
      {/cal_cell_content_today}

      {cal_cell_no_content}
        <div class="day_num">{day}</div>
      {/cal_cell_no_content}

      {cal_cell_no_content_today}
        <div class="today"><div class="day_num">{day}</div></div>
      {/cal_cell_no_content_today}
    ';

js代码在我看来:

$(document).ready(function(){
var date;
   // === Prepare calendar === //
   $('.calendar .day').click(function() {
        day_num = $(this).find('.day_num').html();
        $("#activityModal").modal('toggle');

        $('#add-event-submit').click(function(){
                var hrs = document.getElementById('activityHrs').value;
                var note = document.getElementById('activityNotes').value;
                var cat = document.getElementById('activityCats');
                var selectedCat = cat.options[cat.selectedIndex].text;

            var message = "Date: " + date + "\n";
                message += "hrs: " + hrs + "\n";
                message += "category: " + selectedCat + "\n";
                message += "note: " + note;
                message += "day num: " + day_num;


                //alert(message);


                if (hrs != null && selectedCat !=null && note !=null) {

                    $.ajax({
                        url: window.location,
                        type: 'POST',
                        data: {
                            day: day_num,
                            hours: hrs,
                            category: selectedCat,
                            notes: note
                        },
                        success: function(msg) {
                            location.reload();
                        }
                    });
                }
        });
    });
});
4

0 回答 0