大家好,感谢您花时间阅读我的问题。
我正在尝试创建一个事件日历,用户可以在其中将数据输入日历。
如何在同一页面上显示两个月的日历(例如并排显示 2012 年 12 月和 2013 年 1 月,而不是通过链接显示。)
我从http://net.tutsplus.com/tutorials/php/codeigniter-from-scratch-the-calendar-library/获得了我的代码
很感谢任何形式的帮助。=)
//CONTROLLER
Mycal 类扩展 CI_Controller {
public function index() {
$this->display();
}
function display($year = null, $month = null){
if (!$year) {
$year = date('Y');
}
if (!$month) {
$month = date('m');
}
$this->load->model('Mycal_model');
if($day = $this->input->post('day')){
$this->Mycal_model->add_calendar_data(
"$year-$month-$day",
$this->input->post('data')
);
}
$data['calendar'] = $this->Mycal_model->generate($year, $month);
$this->load->view('mycal_view', $data);
}
}
//模型
类 Mycal_model 扩展 CI_Model{
function get_calendar_data($year, $month){
$query = $this->db->select('date, data')->from('calendar')
->like('date', "$year-$month", 'after')->get();
$cal_data = array();
foreach ($query->result() as $row){
$cal_data[substr($row->date,8,2)] = $row->data;
}
return $cal_data;
}
function add_calendar_data($date, $data){
if($this->db->select('date')->from('calendar')
->where('date', $date)->count_all_results()) {
$this->db->where('date', $date)->update('calendar', array(
'date'=>$date,
'data'=>$data
));
}else{
$this->db->insert('calendar', array(
'date'=>$date,
'data'=>$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)
}
function generate ($year, $month){
// to generate 2nd calendar for the next month?
$this->load->library('calendar', $this->conf);
$cal_data = $this->get_calendar_data($year, $month+1);
return $this->calendar->generate($year, $month+1, $cal_data)
}
//看法
<?php echo $calendar; ?>
// to generate 2nd calendar for the next month?
<?php echo $calendar2; ?>
<script type="text/javascript">
$(document).ready(function() {
$('.calendar .day').click(function() {
day_num = $(this).find('.day_num').html();
day_data = prompt('Enter Stuff', $(this).find('.content').html());
if(day_data !=null){
$.ajax({
url: window.location,
type: 'POST',
data: {
day: day_num,
data: day_data
},
success: function(msg){
location.reload();
}
});
}
});
});
</script>