php实现的农历算法实例

正文实例汇报了php完成的公历算法。分享给我们供我们参谋。具体如下:

本文实例呈报了Zend
Framework教程之视图组件Zend_View用法。分享给大家供我们参照他事他说加以考察,具体如下:

翻开系统版本命令

[root@VM_176_162_centos ~]# cat /etc/centos-release
CentOS Linux release 7.3.1611 (Core)

phpfunction lunarcalendar ($month, $year){ global $lnlunarcalendar; /** * Lunar calendar 博大精深的农历 * 原始数据和算法思路来自 S&S */ /* 农历每月的天数。 每个元素为一年。每个元素中的数据为: [0]是闰月在哪个月,0为无闰月; [1]到[13]是每年12或13个月的每月天数; [14]是当年的天干次序, [15]是当年的地支次序 */ $everymonth = array( 0 = array(8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 29, 30, 7, 1), 1 = array(0, 29, 30, 29, 29, 30, 29, 30, 29, 30, 30, 30, 29, 0, 8, 2), 2 = array(0, 30, 29, 30, 29, 29, 30, 29, 30, 29, 30, 30, 30, 0, 9, 3), 3 = array(5, 29, 30, 29, 30, 29, 29, 30, 29, 29, 30, 30, 29, 30, 10, 4), 4 = array(0, 30, 30, 29, 30, 29, 29, 30, 29, 29, 30, 30, 29, 0, 1, 5), 5 = array(0, 30, 30, 29, 30, 30, 29, 29, 30, 29, 30, 29, 30, 0, 2, 6), 6 = array(4, 29, 30, 30, 29, 30, 29, 30, 29, 30, 29, 30, 29, 30, 3, 7), 7 = array(0, 29, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30, 29, 0, 4, 8), 8 = array(0, 30, 29, 29, 30, 30, 29, 30, 29, 30, 30, 29, 30, 0, 5, 9), 9 = array(2, 29, 30, 29, 29, 30, 29, 30, 29, 30, 30, 30, 29, 30, 6, 10), 10 = array(0, 29, 30, 29, 29, 30, 29, 30, 29, 30, 30, 30, 29, 0, 7, 11), 11 = array(6, 30, 29, 30, 29, 29, 30, 29, 29, 30, 30, 29, 30, 30, 8, 12), 12 = array(0, 30, 29, 30, 29, 29, 30, 29, 29, 30, 30, 29, 30, 0, 9, 1), 13 = array(0, 30, 30, 29, 30, 29, 29, 30, 29, 29, 30, 29, 30, 0, 10, 2), 14 = array(5, 30, 30, 29, 30, 29, 30, 29, 30, 29, 30, 29, 29, 30, 1, 3), 15 = array(0, 30, 29, 30, 30, 29, 30, 29, 30, 29, 30, 29, 30, 0, 2, 4), 16 = array(0, 29, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30, 29, 0, 3, 5), 17 = array(2, 30, 29, 29, 30, 29, 30, 30, 29, 30, 30, 29, 30, 29, 4, 6), 18 = array(0, 30, 29, 29, 30, 29, 30, 29, 30, 30, 29, 30, 30, 0, 5, 7), 19 = array(7, 29, 30, 29, 29, 30, 29, 29, 30, 30, 29, 30, 30, 30, 6, 8), 20 = array(0, 29, 30, 29, 29, 30, 29, 29, 30, 30, 29, 30, 30, 0, 7, 9), 21 = array(0, 30, 29, 30, 29, 29, 30, 29, 29, 30, 29, 30, 30, 0, 8, 10), 22 = array(5, 30, 29, 30, 30, 29, 29, 30, 29, 29, 30, 29, 30, 30, 9, 11), 23 = array(0, 29, 30, 30, 29, 30, 29, 30, 29, 29, 30, 29, 30, 0, 10, 12), 24 = array(0, 29, 30, 30, 29, 30, 30, 29, 30, 29, 30, 29, 29, 0, 1, 1), 25 = array(4, 30, 29, 30, 29, 30, 30, 29, 30, 30, 29, 30, 29, 30, 2, 2), 26 = array(0, 29, 29, 30, 29, 30, 29, 30, 30, 29, 30, 30, 29, 0, 3, 3), 27 = array(0, 30, 29, 29, 30, 29, 30, 29, 30, 29, 30, 30, 30, 0, 4, 4), 28 = array(2, 29, 30, 29, 29, 30, 29, 29, 30, 29, 30, 30, 30, 30, 5, 5), 29 = array(0, 29, 30, 29, 29, 30, 29, 29, 30, 29, 30, 30, 30, 0, 6, 6), 30 = array(6, 29, 30, 30, 29, 29, 30, 29, 29, 30, 29, 30, 30, 29, 7, 7), 31 = array(0, 30, 30, 29, 30, 29, 30, 29, 29, 30, 29, 30, 29, 0, 8, 8), 32 = array(0, 30, 30, 30, 29, 30, 29, 30, 29, 29, 30, 29, 30, 0, 9, 9), 33 = array(5, 29, 30, 30, 29, 30, 30, 29, 30, 29, 30, 29, 29, 30, 10, 10), 34 = array(0, 29, 30, 29, 30, 30, 29, 30, 29, 30, 30, 29, 30, 0, 1, 11), 35 = array(0, 29, 29, 30, 29, 30, 29, 30, 30, 29, 30, 30, 29, 0, 2, 12), 36 = array(3, 30, 29, 29, 30, 29, 29, 30, 30, 29, 30, 30, 30, 29, 3, 1), 37 = array(0, 30, 29, 29, 30, 29, 29, 30, 29, 30, 30, 30, 29, 0, 4, 2), 38 = array(7, 30, 30, 29, 29, 30, 29, 29, 30, 29, 30, 30, 29, 30, 5, 3), 39 = array(0, 30, 30, 29, 29, 30, 29, 29, 30, 29, 30, 29, 30, 0, 6, 4), 40 = array(0, 30, 30, 29, 30, 29, 30, 29, 29, 30, 29, 30, 29, 0, 7, 5), 41 = array(6, 30, 30, 29, 30, 30, 29, 30, 29, 29, 30, 29, 30, 29, 8, 6), 42 = array(0, 30, 29, 30, 30, 29, 30, 29, 30, 29, 30, 29, 30, 0, 9, 7), 43 = array(0, 29, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30, 29, 0, 10, 8), 44 = array(4, 30, 29, 30, 29, 30, 29, 30, 29, 30, 30, 29, 30, 30, 1, 9), 45 = array(0, 29, 29, 30, 29, 29, 30, 29, 30, 30, 30, 29, 30, 0, 2, 10), 46 = array(0, 30, 29, 29, 30, 29, 29, 30, 29, 30, 30, 29, 30, 0, 3, 11), 47 = array(2, 30, 30, 29, 29, 30, 29, 29, 30, 29, 30, 29, 30, 30, 4, 12), 48 = array(0, 30, 29, 30, 29, 30, 29, 29, 30, 29, 30, 29, 30, 0, 5, 1), 49 = array(7, 30, 29, 30, 30, 29, 30, 29, 29, 30, 29, 30, 29, 30, 6, 2), 50 = array(0, 29, 30, 30, 29, 30, 30, 29, 29, 30, 29, 30, 29, 0, 7, 3), 51 = array(0, 30, 29, 30, 30, 29, 30, 29, 30, 29, 30, 29, 30, 0, 8, 4), 52 = array(5, 29, 30, 29, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30, 9, 5), 53 = array(0, 29, 30, 29, 29, 30, 30, 29, 30, 30, 29, 30, 29, 0, 10, 6), 54 = array(0, 30, 29, 30, 29, 29, 30, 29, 30, 30, 29, 30, 30, 0, 1, 7), 55 = array(3, 29, 30, 29, 30, 29, 29, 30, 29, 30, 29, 30, 30, 30, 2, 8), 56 = array(0, 29, 30, 29, 30, 29, 29, 30, 29, 30, 29, 30, 30, 0, 3, 9), 57 = array(8, 30, 29, 30, 29, 30, 29, 29, 30, 29, 30, 29, 30, 29, 4, 10), 58 = array(0, 30, 30, 30, 29, 30, 29, 29, 30, 29, 30, 29, 30, 0, 5, 11), 59 = array(0, 29, 30, 30, 29, 30, 29, 30, 29, 30, 29, 30, 29, 0, 6, 12), 60 = array(6, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30, 29, 30, 29, 7, 1), 61 = array(0, 30, 29, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30, 0, 8, 2), 62 = array(0, 29, 30, 29, 29, 30, 29, 30, 30, 29, 30, 30, 29, 0, 9, 3), 63 = array(4, 30, 29, 30, 29, 29, 30, 29, 30, 29, 30, 30, 30, 29, 10, 4), 64 = array(0, 30, 29, 30, 29, 29, 30, 29, 30, 29, 30, 30, 30, 0, 1, 5), 65 = array(0, 29, 30, 29, 30, 29, 29, 30, 29, 29, 30, 30, 29, 0, 2, 6), 66 = array(3, 30, 30, 30, 29, 30, 29, 29, 30, 29, 29, 30, 30, 29, 3, 7), 67 = array(0, 30, 30, 29, 30, 30, 29, 29, 30, 29, 30, 29, 30, 0, 4, 8), 68 = array(7, 29, 30, 29, 30, 30, 29, 30, 29, 30, 29, 30, 29, 30, 5, 9), 69 = array(0, 29, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30, 29, 0, 6, 10), 70 = array(0, 30, 29, 29, 30, 29, 30, 30, 29, 30, 30, 29, 30, 0, 7, 11), 71 = array(5, 29, 30, 29, 29, 30, 29, 30, 29, 30, 30, 30, 29, 30, 8, 12), 72 = array(0, 29, 30, 29, 29, 30, 29, 30, 29, 30, 30, 29, 30, 0, 9, 1), 73 = array(0, 30, 29, 30, 29, 29, 30, 29, 29, 30, 30, 29, 30, 0, 10, 2), 74 = array(4, 30, 30, 29, 30, 29, 29, 30, 29, 29, 30, 30, 29, 30, 1, 3), 75 = array(0, 30, 30, 29, 30, 29, 29, 30, 29, 29, 30, 29, 30, 0, 2, 4), 76 = array(8, 30, 30, 29, 30, 29, 30, 29, 30, 29, 29, 30, 29, 30, 3, 5), 77 = array(0, 30, 29, 30, 30, 29, 30, 29, 30, 29, 30, 29, 29, 0, 4, 6), 78 = array(0, 30, 29, 30, 30, 29, 30, 30, 29, 30, 29, 30, 29, 0, 5, 7), 79 = array(6, 30, 29, 29, 30, 29, 30, 30, 29, 30, 30, 29, 30, 29, 6, 8), 80 = array(0, 30, 29, 29, 30, 29, 30, 29, 30, 30, 29, 30, 30, 0, 7, 9), 81 = array(0, 29, 30, 29, 29, 30, 29, 29, 30, 30, 29, 30, 30, 0, 8, 10), 82 = array(4, 30, 29, 30, 29, 29, 30, 29, 29, 30, 29, 30, 30, 30, 9, 11), 83 = array(0, 30, 29, 30, 29, 29, 30, 29, 29, 30, 29, 30, 30, 0, 10, 12), 84 = array(10, 30, 29, 30, 30, 29, 29, 30, 29, 29, 30, 29, 30, 30, 1, 1), 85 = array(0, 29, 30, 30, 29, 30, 29, 30, 29, 29, 30, 29, 30, 0, 2, 2), 86 = array(0, 29, 30, 30, 29, 30, 30, 29, 30, 29, 30, 29, 29, 0, 3, 3), 87 = array(6, 30, 29, 30, 29, 30, 30, 29, 30, 30, 29, 30, 29, 29, 4, 4), 88 = array(0, 30, 29, 30, 29, 30, 29, 30, 30, 29, 30, 30, 29, 0, 5, 5), 89 = array(0, 30, 29, 29, 30, 29, 29, 30, 30, 29, 30, 30, 30, 0, 6, 6), 90 = array(5, 29, 30, 29, 29, 30, 29, 29, 30, 29, 30, 30, 30, 30, 7, 7), 91 = array(0, 29, 30, 29, 29, 30, 29, 29, 30, 29, 30, 30, 30, 0, 8, 8), 92 = array(0, 29, 30, 30, 29, 29, 30, 29, 29, 30, 29, 30, 30, 0, 9, 9), 93 = array(3, 29, 30, 30, 29, 30, 29, 30, 29, 29, 30, 29, 30, 29, 10, 10), 94 = array(0, 30, 30, 30, 29, 30, 29, 30, 29, 29, 30, 29, 30, 0, 1, 11), 95 = array(8, 29, 30, 30, 29, 30, 29, 30, 30, 29, 29, 30, 29, 30, 2, 12), 96 = array(0, 29, 30, 29, 30, 30, 29, 30, 29, 30, 30, 29, 29, 0, 3, 1), 97 = array(0, 30, 29, 30, 29, 30, 29, 30, 30, 29, 30, 30, 29, 0, 4, 2), 98 = array(5, 30, 29, 29, 30, 29, 29, 30, 30, 29, 30, 30, 29, 30, 5, 3), 99 = array(0, 30, 29, 29, 30, 29, 29, 30, 29, 30, 30, 30, 29, 0, 6, 4), 100 = array(0, 30, 30, 29, 29, 30, 29, 29, 30, 29, 30, 30, 29, 0, 7, 5), 101 = array(4, 30, 30, 29, 30, 29, 30, 29, 29, 30, 29, 30, 29, 30, 8, 6), 102 = array(0, 30, 30, 29, 30, 29, 30, 29, 29, 30, 29, 30, 29, 0, 9, 7), 103 = array(0, 30, 30, 29, 30, 30, 29, 30, 29, 29, 30, 29, 30, 0, 10, 8), 104 = array(2, 29, 30, 29, 30, 30, 29, 30, 29, 30, 29, 30, 29, 30, 1, 9), 105 = array(0, 29, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30, 29, 0, 2, 10), 106 = array(7, 30, 29, 30, 29, 30, 29, 30, 29, 30, 30, 29, 30, 30, 3, 11), 107 = array(0, 29, 29, 30, 29, 29, 30, 29, 30, 30, 30, 29, 30, 0, 4, 12), 108 = array(0, 30, 29, 29, 30, 29, 29, 30, 29, 30, 30, 29, 30, 0, 5, 1), 109 = array(5, 30, 30, 29, 29, 30, 29, 29, 30, 29, 30, 29, 30, 30, 6, 2), 110 = array(0, 30, 29, 30, 29, 30, 29, 29, 30, 29, 30, 29, 30, 0, 7, 3), 111 = array(0, 30, 29, 30, 30, 29, 30, 29, 29, 30, 29, 30, 29, 0, 8, 4), 112 = array(4, 30, 29, 30, 30, 29, 30, 29, 30, 29, 30, 29, 30, 29, 9, 5), 113 = array(0, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30, 29, 30, 0, 10, 6), 114 = array(9, 29, 30, 29, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30, 1, 7), 115 = array(0, 29, 30, 29, 29, 30, 29, 30, 30, 30, 29, 30, 29, 0, 2, 8), 116 = array(0, 30, 29, 30, 29, 29, 30, 29, 30, 30, 29, 30, 30, 0, 3, 9), 117 = array(6, 29, 30, 29, 30, 29, 29, 30, 29, 30, 29, 30, 30, 30, 4, 10), 118 = array(0, 29, 30, 29, 30, 29, 29, 30, 29, 30, 29, 30, 30, 0, 5, 11), 119 = array(0, 30, 29, 30, 29, 30, 29, 29, 30, 29, 29, 30, 30, 0, 6, 12), 120 = array(4, 29, 30, 30, 30, 29, 30, 29, 29, 30, 29, 30, 29, 30, 7, 1) ); $mten = $lnlunarcalendar['tiangan'];// 农历天干 $mtwelve = $lnlunarcalendar['dizhi'];// 农历地支 $mmonth = $lnlunarcalendar['month'];// 农历月份 $mday = $lnlunarcalendar['day'];// 农历日 // 阳历总天数 至1900年12月21日 $total = 69 * 365 + 17 + 11; //1970年1月1日前的就不算了 if ($year == "" || $month == "" || ($year  1970 or $year  2020)) return ''; //超出这个范围不计算 // 计算到所求日期阳历的总天数-自1900年12月21日始 for ($y = 1970; $y  $year;$y++) {// 先算年的和 $total += 365; if ($y % 4 == 0) $total ++; } // 再加当年的几个月 $total += gmdate("z", gmmktime(0, 0, 0, $month, 1, $year)); // 用农历的天数累加来判断是否超过阳历的天数 $flag1 = 0; //判断跳出循环的条件 $lcj = 0; while ($lcj = 120) { $lci = 1; while ($lci = 13) { @$mtotal += $everymonth[$lcj][$lci]; if ($mtotal = $total) { $flag1 = 1; break; } $lci++; } if ($flag1 == 1) break; $lcj++; } // 由上,得到的 $lci 为当前农历月, $lcj 为当前农历年 // 计算所求月份1号的农历日期 $fisrtdaylunar = $everymonth[$lcj][$lci] - ($mtotal - $total); $results['year'] = $mten[$everymonth[$lcj][14]] . $mtwelve[$everymonth[$lcj][15]]; //当前是什么年 $daysthismonth = gmdate("t", gmmktime(0, 0, 0, $month, 1, $year)); //当前月共几天 $op = 1; for ($i = 1; $i = $daysthismonth; $i++) { $possiblelunarday = $fisrtdaylunar + $op-1; //理论上叠加后的农历日 if ($possiblelunarday = $everymonth[$lcj][$lci]) { // 在本月的天数范畴内 $results[$i] = $mday[$possiblelunarday]; $op += 1; } else { // 不在本月的天数范畴内 $results[$i] = $mday[1]; //退回到1日 $fisrtdaylunar = 1; $op = 2; $curmonthnum = ($everymonth[$lcj][0] != 0)  13 : 12; //当年有几个月 if ($lci + 1  $curmonthnum) { // 第13/14个月了,转到下一年 $lci = 1; $lcj = $lcj + 1; // 换年头了,把新一年的天干地支也写上 $results['year'] .= '/' . $mten[$everymonth[$lcj][14]] . $mtwelve[$everymonth[$lcj][15]]; } else { // 还在这年里 $lci = $lci + 1; $lcj = $lcj; } } if ($results[$i] == $mday[1]) { // 每月的初一应该显示当月是什么月 if ($everymonth[$lcj][0] != 0) { // 有闰月的年 $monthss = ($lci  $everymonth[$lcj][0])  ($lci-1) : $lci; //闰月后的月数-1 if ($lci == $everymonth[$lcj][0] + 1) { // 这个月正好是闰月 $monthssshow = $mmonth[0] . $mmonth[$monthss]; //前面加个闰字 $runyue = 1; } else { $monthssshow = $mmonth[$monthss]; } } else { $monthss = $lci; $monthssshow = $mmonth[$monthss]; } if ($monthss = 10 && @$runyue != 1){ //只有1个字的月加上‘月'字 $monthssshow .= $mmonth[13]; } $results[$i] = $monthssshow; } } return $results;}// 忘了加上这个:农历用字$lnlunarcalendar = array( 'tiangan' = array("未知", "甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸"), 'dizhi' = array("未知", "子年", "丑年", "寅年", "卯年", "辰年", "巳年", "午年", "未年", "申年", "酉年", "戌年", "亥年"), 'month' = array("闰", "正", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二", "月"), 'day' = array("未知", "初一", "初二", "初三", "初四", "初五", "初六", "初七", "初八", "初九", "初十", "十一", "十二", "十三", "十四", "十五", "十六", "十七", "十八", "十九", "二十", "廿一", "廿二", "廿三", "廿四", "廿五", "廿六", "廿七", "廿八", "廿九", "三十"));print_r(lunarcalendar(8,2015));

Zend_View是Zend Framework的视图组件,MVC中的视图层。
Zend_View也是选拔的直接对客户显示的页面。这里介绍一下Zend_View的贯彻类,以至哪些和Controller结合在一块儿的。

1.若在此之前设置过此外版本PHP,先删除

# yum remove php*

运作结果如下:

View的实现

2.rpm安装PHP7相应的yum源

CentOS/RHEL 7.x:
# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
CentOS/RHEL 6.x:
# rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm

Array( [year] = 乙未年 [1] = 十七 [2] = 十八 [3] = 十九 [4] = 二十 [5] = 廿一 [6] = 廿二 [7] = 廿三 [8] = 廿四 [9] = 廿五 [10] = 廿六 [11] = 廿七 [12] = 廿八 [13] = 廿九 [14] = 七月 [15] = 初二 [16] = 初三 [17] = 初四 [18] = 初五 [19] = 初六 [20] = 初七 [21] = 初八 [22] = 初九 [23] = 初十 [24] = 十一 [25] = 十二 [26] = 十三 [27] = 十四 [28] = 十五 [29] = 十六 [30] = 十七 [31] = 十八)

Zend_View的落实重大是通过如下目录的类达成:

3.yum安装PHP7

# yum install php70w

期望本文所述对大家的php程序设计有所帮忙。

root@coder-671T-M:/library/Zend# tree | grep View.php│ └── View/├──
View.php

4.设置其余插件(选装)

这一步就算闲麻烦的话一贯在上一步试行下边那条命令就能够(提示有冲突的话依照提醒过滤冲突就可以)

意为安装全部插件```

php70w
php70w-opcache
php70w-bcmath
php70w-cli
php70w-common
php70w-dba
php70w-devel
php70w-embedded
php70w-enchant
php70w-fpm
php70w-gd
php70w-imap
php70w-interbase
php70w-intl
php70w-ldap
php70w-mbstring
php70w-mcrypt
php70w-mysql
php70w-mysqlnd
php70w-odbc
php70w-opcache
php70w-pdo
php70w-pdo_dblib
php70w-pear
php70w-pecl-apcu
php70w-pecl-imagick
php70w-pecl-xdebug
php70w-pgsql
php70w-phpdbg
php70w-process
php70w-pspell
php70w-recode
php70w-snmp
php70w-soap
php70w-tidy
php70w-xml
php70w-xmlrpc“`

root@coder-671T-M:/library/Zend/View# tree.├── Abstract.php├──
Exception.php├── Helper│ ├── Abstract.php│ ├── Action.php│ ├──
BaseUrl.php│ ├── Currency.php│ ├── Cycle.php│ ├── DeclareVars.php│ ├──
Doctype.php│ ├── Fieldset.php│ ├── FormButton.php│ ├── FormCheckbox.php│
├── FormElement.php│ ├── FormErrors.php│ ├── FormFile.php│ ├──
FormHidden.php│ ├── FormImage.php│ ├── FormLabel.php│ ├──
FormMultiCheckbox.php│ ├── FormNote.php│ ├── FormPassword.php│ ├──
Form.php│ ├── FormRadio.php│ ├── FormReset.php│ ├── FormSelect.php│ ├──
FormSubmit.php│ ├── FormTextarea.php│ ├── FormText.php│ ├──
Gravatar.php│ ├── HeadLink.php│ ├── HeadMeta.php│ ├── HeadScript.php│
├── HeadStyle.php│ ├── HeadTitle.php│ ├── HtmlElement.php│ ├──
HtmlFlash.php│ ├── HtmlList.php│ ├── HtmlObject.php│ ├── HtmlPage.php│
├── HtmlQuicktime.php│ ├── InlineScript.php│ ├── Interface.php│ ├──
Json.php│ ├── Layout.php│ ├── Navigation│ │ ├── Breadcrumbs.php│ │ ├──
HelperAbstract.php│ │ ├── Helper.php│ │ ├── Links.php│ │ ├── Menu.php│ │
└── Sitemap.php│ ├── Navigation.php│ ├── PaginationControl.php│ ├──
Partial│ │ └── Exception.php│ ├── PartialLoop.php│ ├── Partial.php│ ├──
Placeholder│ │ ├── Container│ │ │ ├── Abstract.php│ │ │ ├──
Exception.php│ │ │ └── Standalone.php│ │ ├── Container.php│ │ ├──
Registry│ │ │ └── Exception.php│ │ └── Registry.php│ ├──
Placeholder.php│ ├── RenderToPlaceholder.php│ ├── ServerUrl.php│ ├──
TinySrc.php│ ├── Translate.php│ ├── Url.php│ └── UserAgent.php├──
Interface.php└── Stream.php

5. 装置完成,测量检验是否安装成功

# php -v

6 directories, 70 files

6.要运行PHP网页,要启动php-fpm解释器

# service php-fpm start

Zend_View和Zend_Controller的整合

主要在Zend_Controller_Action类中,

/** * Initialize View object * * Initializes {@link $view} if not otherwise a Zend_View_Interface. * * If {@link $view} is not otherwise set, instantiates a new Zend_View * object, using the 'views' subdirectory at the same level as the * controller directory for the current module as the base directory. * It uses this to set the following: * - script path = views/scripts/ * - helper path = views/helpers/ * - filter path = views/filters/ * * @return Zend_View_Interface * @throws Zend_Controller_Exception if base view directory does not exist */ public function initView() { if (!$this->getInvokeArg && $this->_helper->hasHelper { return $this->view; } require_once 'Zend/View/Interface.php'; if  && ($this->view instanceof Zend_View_Interface)) { return $this->view; } $request = $this->getRequest(); $module = $request->getModuleName(); $dirs = $this->getFrontController()->getControllerDirectory || !isset { $module = $this->getFrontController->getDefaultModule(); } $baseDir = dirname . DIRECTORY_SEPARATOR . 'views'; if (!file_exists || !is_dir { require_once 'Zend/Controller/Exception.php'; throw new Zend_Controller_Exception('Missing base view directory ; } require_once 'Zend/View.php'; $this->view = new Zend_View(array('basePath' => $baseDir)); return $this->view; } /** * Render a view * * Renders a view. By default, views are found in the view script path as * /.phtml. You may change the script suffix by * resetting {@link $viewSuffix}. You may omit the controller directory * prefix by specifying boolean true for $noController. * * By default, the rendered contents are appended to the response. You may * specify the named body content segment to set by specifying a $name. * * @see Zend_Controller_Response_Abstract::appendBody() * @param string|null $action Defaults to action registered in request object * @param string|null $name Response object named path segment to use; defaults to null * @param bool $noController Defaults to false; i.e. use controller name as subdir in which to search for view script * @return void */ public function render($action = null, $name = null, $noController = false) { if (!$this->getInvokeArg && $this->_helper->hasHelper { return $this->_helper->viewRenderer->render($action, $name, $noController); } $view = $this->initView(); $script = $this->getViewScript($action, $noController); $this->getResponse()->appendBody( $view->render; } /** * Render a given view script * * Similar to {@link render()}, this method renders a view script. Unlike render(), * however, it does not autodetermine the view script via {@link getViewScript()}, * but instead renders the script passed to it. Use this if you know the * exact view script name and path you wish to use, or if using paths that do not * conform to the spec defined with getViewScript(). * * By default, the rendered contents are appended to the response. You may * specify the named body content segment to set by specifying a $name. * * @param string $script * @param string $name * @return void */ public function renderScript($script, $name = null) { if (!$this->getInvokeArg && $this->_helper->hasHelper { return $this->_helper->viewRenderer->renderScript; } $view = $this->initView(); $this->getResponse()->appendBody( $view->render; }

Zend_View.php类

_useViewStream =  ini_get ? false : true; if ($this->_useViewStream) { if (!in_array('zend.view', stream_get_wrappers { require_once 'Zend/View/Stream.php'; stream_wrapper_register('zend.view', 'Zend_View_Stream'); } } if (array_key_exists('useStreamWrapper', $config)) { $this->setUseStreamWrapper($config['useStreamWrapper']); } parent::__construct; } /** * Set flag indicating if stream wrapper should be used if short_open_tag is off * * @param bool $flag * @return Zend_View */ public function setUseStreamWrapper { $this->_useStreamWrapper =  $flag; return $this; } /** * Should the stream wrapper be used if short_open_tag is off? * * @return bool */ public function useStreamWrapper() { return $this->_useStreamWrapper; } /** * Includes the view script in a scope with only public $this variables. * * @param string The view script to execute. */ protected function _run() { if ($this->_useViewStream && $this->useStreamWrapper { include 'zend.view://' . func_get_arg; } else { include func_get_arg; } }}

暗中同意境况会自动通过Controller会通过render方法来实例化Zend_View,
然后rener到相应的视图像和文字件中。当然能够本身实例化Zend_View,然后利用。

action私下认可指向的文书是和action的名号相似,假设要钦定视图像和文字件,能够通过$this->render的相干措施钦赐.也足以经过addScriptPath和setScriptPath设置视图像和文字件的目录。

$view = new Zend_View();$view->addScriptPath;$view->addScriptPath;// 如果调用 $view->render, Zend_View 将// 首先查找 "/www/app/myviews/example.php", 找不到再找"/www/app/viewscomm/example.php", 如果还找不到,最后查找当前目录下/的"example.php".

Zend_View的常用方法

public function __construct

array, 'encoding' => array;

escape、encoding、basePath、basePathPrefix、scriptPath、helperPath、
helperPathPrefix、filterPath、filterPathPrefix、filterpublic function
getEngine() Return the template engine object

public function init(State of Qatar开端化函数

/*** Given a base path, sets the script, helper, and filter paths relative to it** Assumes a directory structure of:* * basePath/* scripts/* helpers/* filters/* ** @param string $path* @param string $prefix Prefix to use for helper and filter paths* @return Zend_View_Abstract*/public function setBasePath($path, $classPrefix = 'Zend_View')/*** Given a base path, add script, helper, and filter paths relative to it** Assumes a directory structure of:* * basePath/* scripts/* helpers/* filters/* ** @param string $path* @param string $prefix Prefix to use for helper and filter paths* @return Zend_View_Abstract*/public function addBasePath($path, $classPrefix = 'Zend_View')public function addScriptPathAdds to the stack of view script paths in LIFO order.public function setScriptPath Resets the stack of view script paths.public function getScriptPathReturn full path to a view script specified by $namepublic function getScriptPaths()Returns an array of all currently set script pathspublic function addHelperPath($path, $classPrefix = 'Zend_View_Helper_')Adds to the stack of helper paths in LIFO order.public function setHelperPath($path, $classPrefix = 'Zend_View_Helper_')Resets the stack of helper paths.public function getHelperPath Get full path to a helper class file specified by $namepublic function getHelperPaths()Returns an array of all currently set helper pathspublic function getHelper Get a helper by namepublic function getHelpers()Get array of all active helperspublic function getAllPaths() Return associative array of path types => pathspublic function setEscape/*** Assigns variables to the view script via differing strategies.** Zend_View::assign assigns a variable called 'name'* with the corresponding $value.** Zend_View::assign assigns the array keys as variable* names (with the corresponding array values).** @see __set()* @param string|array The assignment strategy to use.* @param mixed  If assigning a named variable, use this* as the value.* @return Zend_View_Abstract Fluent interface* @throws Zend_View_Exception if $spec is neither a string nor an array,* or if an attempt to set a private or protected member is detected*/public function assign

在controller的action能够透过assign传递参数到视图脚本。

$this->view->assign;$this->view->assign;$this->view->assign;

$this->view->roles=$roles;$this->view->a=$a;public function render Processes a view script and returns the output.public function escape:Escapes a value for output in a view script.public function setEncoding Set encoding to use with htmlentities() and htmlspecialchars()public function getEncoding() :Return current escape encoding

视图脚本文件中的不胜枚举用法

$this->roles

接收一些大范围的臂膀方法:

$this->baseUrl;$this->paginationControl

在bootstrap初始化view或者controller的init文件中

/** * Initialize the common view helper */protected function _initViewHelper(){ $boot=$this->bootstrap; $view = $boot->getResource; $view->setHelperPath('Sql/View/Helper', 'Sql_View_Helper');}

/** * * @return void */public function listAction(){ $this->view->assign;}

越来越多关于zend相关内容感兴趣的读者可查看本站专题:《Zend
FrameWork框架入门教程》、《php卓越开荒框架总括》、《Yii框架入门及常用技能总括》、《ThinkPHP入门教程》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php不以为奇数据库操作才具汇总》

仰望本文所述对我们PHP程序设计具有助于。

You can leave a response, or trackback from your own site.

Leave a Reply

网站地图xml地图