PHP日历问题

时间:2013-02-21 20:45:46

标签: php object

我正在尝试创建的日历存在一个小问题。它没有正确输出我的数组,任何想法?这些数字不会出现在日期中。

这是我的主要输出文件:

<?php 

require('date_class.php');

?>

<!DOCTYPE html>
<html>
    <head>
        <title>Calendar || That sorta works</title>
    </head>
    <body>
        <h1>Calendar</h1>

        <?php echo $date_class->get_day(); ?>
        <?php echo $date_class->get_month(); ?>
        <?php echo $date_class->get_year(); ?>


        <?php
            $weekdays = array('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun');
        ?>

        <?php foreach($dates as $month => $weeks) { ?>
        <table>
            <tr>
                <th><?php echo implode('</th><th>', $weekdays); ?></th>
            </tr>
            <?php foreach($weeks as $week => $days){ ?>
            <tr>
                <?php foreach($weekdays as $day){ ?>
                <td>
                    <?php echo isset($days[$day]) ? $days[$day] : '&nbsp'; ?>
                </td>               
                <?php } ?>
            </tr>
            <?php } ?>
        </table>
        <?php } ?>
    </body>
</html>

这是我的班级文件:

<?php

class Date_class{

    /* Sets our vars within the class */
    public $day;
    public $month;
    public $year;
    public $dates;
    public $syear;

    /* Sets day */
    public function set_day($day){
        $this->day = $day;
    }

    /* Sets month */
    public function set_month($month){
        $this->month = $month;
    }

    /* Sets year */
    public function set_year($year){
        $this->year = $year;
    }

    /* Sets date */
    public function set_date($month, $year){
        $this->date = $day . $month . $year;
    }

    /* Sets dates for set year */
    public function set_all_dates(){
        $this->dates = $dates;
    }


    /* Gets day */
    public function get_day(){
        return $this->day;
    }

    /* Gets month */
    public function get_month(){
        return $this->month;
    }

    /* Gets year */
    public function get_year(){
        return $this->year;
    }

    /* Returns dates for year */
    public function get_all_dates($year){

        $dates = array();

        for($i = 1; $i <= 366; $i++){
            $month = date('m', mktime(0,0,0,0,$i,$year));
            $wk = date('W', mktime(0,0,0,0,$i,$year));
            $wkDay = date('D', mktime(0,0,0,0,$i,$year));
            $day = date('d', mktime(0,0,0,0,$i,$year));

            $dates[$month][$wk][$day] = $wkDay;
        }

        return $dates;
    }

}


/* Sets current day as var */
$day = date("d");

/* Sets current month as var */
$month = date("m");

/* Sets current year as var */
$year = date("Y");


/* Creates class as object */
$date_class = new Date_class();

/* Passes our gregorian variables \m/ into our calendar object */
$date_class->set_day($day);
$date_class->set_month($month);
$date_class->set_year($year);

/* Sets calendar year */
$dates = $date_class->get_all_dates($year);

0 个答案:

没有答案