Czy naprawdę tak ciężko wysilić szare komórki i poszukać samemu na googlach?Jeśli znasz się na PHP to skorzystaj z tego, co ostatnio napisałem:
Calendar.php:
<?php
class Calendar {
protected
$weeks = array(); protected $date;
public function __construct($date) {
$this->generate();
}
protected function generate() {
$year = date('Y', $this->date); $month = date('m', $this->date); $day = date('d', $this->date);
$i = 1;
$week = new Calendar_Week();
while ($i <= date('t', $this->date)) {
if (date('N', $date) == 1
) { if ($week->getCounter() > 0) {
$this->weeks[] = $week;
}
$week = new Calendar_Week();
}
$week->setDay(date('N', $date), $i);
$i++;
}
$this->weeks[] = $week;
}
public function getWeeks() {
return $this->weeks;
}
}
?>
Calendar_Week.php:
<?php
class Calendar_Week {
private $_days;
private $_counter = 0;
public function __construct() {
1 => false,
false,
false,
false,
false,
false,
false
);
}
public function setDay($dayOfWeek, $dayOfMonth) {
$this->_days[$dayOfWeek] = $dayOfMonth;
$this->_counter++;
}
public function getDay($dayOfWeek) {
return $this->_days[$dayOfWeek];
}
public function getDays() {
return $this->_days;
}
public function getCounter() {
return $this->_counter;
}
}
?>
calendar.phtml:
<table id="calendar">
<thead>
<tr>
</tr>
</thead>
<tbody>
<?php foreach ($calendar->getWeeks() as $w): ?>
<tr>
<?php for($i=1; $i<=7; $i++): ?>
<?php if ($w->getDay($i)): ?>
<td
<?= $year.'-'.$month.'-'.sprintf('%02d', $w->getDay($i)) == $date ?
' id="currentDay"' : null ?>><a href="./?date=
<?php echo $year.'-'.$month.'-'.sprintf('%02d', $w->getDay($i)) ?>">
<?= $w->getDay($i) ?></a></td>
<?php else: ?>
<td></td>
<?php endif; ?>
<?php endfor; ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
Wywołanie:
<?php
$calendar = new Calendar($date);
?>
Have fun!