使用日历库codeigniter在顶部显示前三个和下一个箭头的3个月日历:上一个按钮的问题

时间:2019-03-07 13:35:20

标签: javascript php html mysql codeigniter

我正在使用Codegniter 日历库在一张照片(页面)中显示三个月的日历,并在页面顶部显示上一个和下一个按钮。

我的问题:使用“下一个”按钮可以正常工作,但是使用“上一个”按钮,我无法“减少年份”。

即,最初在首页上显示[2019年3月至2019年5月]的日历,单击“下一步”按钮,则显示[2019年6月至2019年8月]的日历:工作正常。

但是,当您单击“上一个”按钮时,它将显示月份的日历[2019年2月,2019年1月, 2019年3月]。应该是 2018年12月,而不是2019年3月。

这是我的代码:

application / controllers / Calendar_controller1.php

public function display($year=null,$month=null){


    if(!$year){

        $year = date('Y');

    }

    if(!$month){

        $month = date('m');
    }

    $this->load->model("cal_model1");
    $data["cur_month_calendar"] = $this->cal_model1->generate($year,$month);
    $data["cur_month1_calendar"] = $this->cal_model1->generate($year,$month+1);
    $data["cur_month2_calendar"] = $this->cal_model1->generate($year,$month+2);

    $data["year"] = $year;
    $data["nxt_month"] = $month+2;
    $data["prev_month"] = $month;


    $this->load->view("cal_view1",$data);
}


 public function build_next_display(){


    $varCurMonth = $this->input->post('month');
    $varCurYear = $this->input->post('year');
    $this->load->model("cal_model1");
     $data["nxt_month1"] = $this->cal_model1->generate($varCurYear,$varCurMonth+1);
    $data["nxt_month2"] = $this->cal_model1->generate($varCurYear,$varCurMonth+2);
    $data["nxt_month3"] = $this->cal_model1->generate($varCurYear,$varCurMonth+3);

    $data["year"] = $varCurYear;
    $data["month"] = $varCurMonth+3;

    //$this->load->view("cal_view1",$data); 

    echo json_encode($data);
} 


     public function build_prev_display(){


    $varCurMonth = $this->input->post('month');
    $varCurYear = $this->input->post('year');
    $this->load->model("cal_model1");
     $data["nxt_month1"] = $this->cal_model1->generate($varCurYear,$varCurMonth-1);
    $data["nxt_month2"] = $this->cal_model1->generate($varCurYear,$varCurMonth-2);
    $data["nxt_month3"] = $this->cal_model1->generate($varCurYear,$varCurMonth-3);

    $data["year"] = $varCurYear;
    $data["month"] = $varCurMonth-1;

    //$this->load->view("cal_view1",$data); 

    echo json_encode($data);
} 

application / models / Cal_model1.php

public  $conf = array();

public function __construct(){



    $this->conf = array(
                'start_day' => 'monday',
                //'show_next_prev' => true,
                //'next_prev_url' => base_url().'Calendar_Controller/display',
                'day_type' => 'short'
    );

    $this->conf['template'] = '

    {table_open}<table border="0" cellpadding="0" cellspacing="0" class="calendar">{/table_open}

    {heading_row_start}<tr class="heading">{/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_row_start}<tr class="weekdays">{/week_row_start}
    {week_day_cell}<td>{week_day}</td>{/week_day_cell}
    {week_row_end}</tr>{/week_row_end}

    {cal_row_start}<tr class="days">{/cal_row_start}
    {cal_cell_start}<td class="day">{/cal_cell_start}
    {cal_cell_start_today}<td>{/cal_cell_start_today}
    {cal_cell_start_other}<td class="other-month">{/cal_cell_start_other}

    {cal_cell_content}
        <div class="day_num">{day}</div>
        <div class="content">{content}</div>
    {/cal_cell_content}
    {cal_cell_content_today}
        <div class="day_num highlight">{day}</div>
        <div class="content">{content}</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="day_num highlight">{day}</div>
    {/cal_cell_no_content_today}

    {cal_cell_blank}&nbsp;{/cal_cell_blank}

    {cal_cell_other}
        <div class="day_num">{day}</div>
    {/cal_cel_other}

    {cal_cell_end}</td>{/cal_cell_end}
    {cal_cell_end_today}</td>{/cal_cell_end_today}
    {cal_cell_end_other}</td>{/cal_cell_end_other}
    {cal_row_end}</tr>{/cal_row_end}




    {table_close}</table>{/table_close}
    ';



}


public function startsWith($string, $startString){

    $len = strlen($startString); 
    return (substr($string, 0, $len) === $startString); 

}


public function get_calendar_data($year,$month){

    $varMonthLen = strlen($month);
    if($varMonthLen == 1){
        $month = '0'.$month;
    }
    $this->db->select('holiday_date,holiday_name');
    $this->db->from('holiday_list');
    $this->db->where('country_id',1);
    $this->db->like('holiday_date',"$year-$month",'after');
    $query=$this->db->get();
    //print_r($this->db->last_query());exit;
    //print_r($query->result());


    $cal_data = array();
    foreach($query->result() as $row){
        $holiday_date = substr($row->holiday_date,8,2);

        $startsWithZero = $this->startsWith($holiday_date,"0");

        if($startsWithZero == true){
            $holiday_date = str_replace('0','',$holiday_date);
        }
        $cal_data[$holiday_date] = $row->holiday_name;  
    }



    return $cal_data; //Issue : 01 -09 Dates  , If you change , this to 1 -9 , it works


}


public function generate($year,$month){

    $this->load->library("calendar",$this->conf);
    $cal_data = $this->get_calendar_data($year,$month);
    //print_r($cal_data);
    return $this->calendar->generate($year,$month,$cal_data);
}

application / views / cal_view1.php

<script src="<?php echo base_url();?>assets/js/jquery.min.js"></script>
<script type="text/javascript">

var year = "<?php echo $year; ?>";
var nxtMonth = "<?php echo $nxt_month; ?>";
var prevMonth = "<?php echo $prev_month; ?>";


$('.previous').click(function(){

//alert("previous");
//alert("year"+year);
//alert("month"+prevMonth);

$.ajax({
   url: "<?php echo base_url();?>Calendar_controller1/build_prev_display",
   type: "POST",
   data: {'month':prevMonth,'year':year},

   dataType: "json",
   success: function (res) {
   
	console.log(res.nxt_month1);
	$('#cur_month_calendar').html('');
	$('#cur_month_calendar').html(res.nxt_month1);
	
	$('#cur_month1_calendar').html('');
	$('#cur_month1_calendar').html(res.nxt_month2);
	
	$('#cur_month2_calendar').html('');
	$('#cur_month2_calendar').html(res.nxt_month3);
	
	year = res.year;
	prevMonth = res.month;
	
  },                   
});


});

$('.next').click(function(){

//alert("next");
//alert("year"+year);
//alert("month"+nxtMonth);



$.ajax({
   url: "<?php echo base_url();?>Calendar_controller1/build_next_display",
   type: "POST",
   data: {'month':nxtMonth,'year':year},

   dataType: "json",
   success: function (res) {
   
	console.log(res.nxt_month1);
	$('#cur_month_calendar').html('');
	$('#cur_month_calendar').html(res.nxt_month1);
	
	$('#cur_month1_calendar').html('');
	$('#cur_month1_calendar').html(res.nxt_month2);
	
	$('#cur_month2_calendar').html('');
	$('#cur_month2_calendar').html(res.nxt_month3);
	
	year = res.year;
	nxtMonth = res.month;
	
  },                   
}); 

});

</script>
.calendar{
	font-family:Arial;
	font-size:12px;
}
table.calendar{
	
	margin:auto;
	border-collapse:collapse;
}
.calendar .days td{
	width:50px;
	height:50px;
	border:2px solid black;
	padding:4px;
	vertical-align:top;
	background-color:#DEF;
	
}

.calendar .days td:hover{

	background-color:#FFF;
	
}

.calendar .weekdays td{
	
	border:2px solid black;
	padding:2px;
	text-align:center;
	background-color : #C0C0C0;
}

.calendar .heading th{
	
	text-transform:uppercase;
    font-size:16px;	
	padding:10px;
	
}

.calendar .highlight{
	
	font-weight:bold;
	color:blue;	
}

.calendar .content{
    
    width: 50px;
    background-color: #bbb;
	border-radius: 50%;
	display: inline-block;
	border: 2px solid green;
    text-align: center;
}

a {
  text-decoration: none;
  display: inline-block;
  padding: 8px 16px;
}

a:hover {
  background-color: #ddd;
  color: black;
}

.previous {
  background-color: #f1f1f1;
  color: black;
 
}

.next {
  background-color: #4CAF50;
  color: white;
}
<a href="#" class="previous">&laquo; </a>
<a href="#" class="next"> &raquo;</a>

<?php //echo $calendar; ?>



<div id="cur_month_calendar">
	<?php echo $cur_month_calendar; ?>
</div>

<div id="cur_month1_calendar">
	<?php echo $cur_month1_calendar; ?>
</div>

<div id="cur_month2_calendar">
	<?php echo $cur_month2_calendar; ?>
</div>

1 个答案:

答案 0 :(得分:0)

下面的代码应做您想要的,但可以简化。我这样写是为了让您了解日期在PHP中的工作方式。作为参考,请查看DateIntervaldate_adddate_sub

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


driver=webdriver.Firefox(executable_path=r'C:\Utility\BrowserDrivers\geckodriver.exe')
driver.get("https://www.safetysign.com/products/7337/ez-pipe-marker")
for product in WebDriverWait(driver, 20).until(EC.visibility_of_all_elements_located((By.XPATH, "//form[@class='product-page-form']//div[@class='sku-contents']//following::ul[1]/li//label[starts-with(@for, 'skuer') and contains(., 'Pipe')]"))):
    WebDriverWait(driver, 20).until(EC.visibility_of(product)).click()
driver.quit()