Providing Forward and Backward Navigation
You can allow the user to move backwards and forwards a month at a time in Month View, or a year at a time in Year View.
This is done be creating a new class which extends the Calendar
class. This new class should define the function getCalendarLink:
getCalendarLink($month, $year)
- Return the URL to link to in order to display a calendar for a given
month/year. You must override this method if you want to activate the
"forward" and "back" feature of the calendar.
Note: If you return an empty string from this function, no navigation link will be displayed. This is the default behaviour.
If the calendar is being displayed in "year" view, $month will be set to zero.
class MyCalendar extends Calendar
{
function getCalendarLink($month, $year)
{
// Redisplay the current page, but with some parameters
// to set the new month and year
$s = getenv('SCRIPT_NAME');
return "$s?month=$month&year=$year";
}
}
You can then display the calendar as follows:
<?
// If no month/year set, use current month/year
$d = getdate(time());
if ($month == "")
{
$month = $d["mon"];
}
if ($year == "")
{
$year = $d["year"];
}
$cal = new MyCalendar;
echo $cal->getMonthView($month, $year);
?>
Which looks like this:
<< | April 2024 | >> | ||||
S | M | T | W | T | F | S |
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 |
- Creating a Simple Calendar
- Creating a Calendar for a Specific Date
- Setting Styles
- Changing the Calendar Labels
- Setting the Start Day
- Setting the Start Month
- Providing Forward and Backward Navigation
- Linking Dates