PHP開發(fā)之制作簡單日歷引用CLASS類
1、new一個(gè)Calendar類
2、初始化兩個(gè)下拉框中的數(shù)據(jù),年份與月份
3、初始化要搜索的年份和月份
4、計(jì)算得出日歷中每一天的數(shù)據(jù)信息,包括css、天數(shù)
引用前面封裝的Calendar類
<?php include_once 'calendar.php'; ?>
?The?include_once()?語句在腳本執(zhí)行期間包含并運(yùn)行指定文件。此行為和?include()?語句類似,唯一區(qū)別是如果該文件中的代碼已經(jīng)被包含了,則不會(huì)再次包含。如同此語句名字暗示的那樣,只會(huì)包含一次。
實(shí)例化這個(gè)類:
<?php $util = new Calendar(); ?>
還需要定義年份和月份數(shù)組用POST方式獲取
<?php $years = array(2014, 2015, 2016, 2017, 2018);//年份選擇自定義 $months = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);//月份數(shù)組 //獲取post的年份數(shù)據(jù) if(empty($_POST['ddlYear'])) { $year = date('Y'); }else { $year = $_POST['ddlYear']; } //獲取post的月份數(shù)據(jù) if(empty($_POST['ddlMonth'])) { $month = date('n'); }else { $month = $_POST['ddlMonth']; } ?>
通過實(shí)例化類獲取threshold方法,caculate方法和draw方法。
<?php $calendar = $util->threshold($year, $month);//獲取各個(gè)邊界值 $caculate = $util->caculate($calendar);//獲取計(jì)算日歷的天數(shù)與樣式 $draws = $util->draw($caculate);//畫表格,設(shè)置table中的tr與td ?>