A very simple, easy to use PHP calendar rendering class.
- php: >=7.4
- ext-calendar: *
Install the latest version with:
composer require 'donatj/simplecalendar'<?php
require '../vendor/autoload.php';
echo '<link rel="stylesheet" href="../src/css/SimpleCalendar.css" />';
$calendar = new donatj\SimpleCalendar('June 2010');
echo $calendar->render();<?php
require '../vendor/autoload.php';
echo '<link rel="stylesheet" href="../src/css/SimpleCalendar.css" />';
$calendar = new donatj\SimpleCalendar;
$calendar->setStartOfWeek('Sunday');
$calendar->addDailyHtml('Sample Event', 'today', 'tomorrow');
$calendar->setWeekDayNames([ 'Sun', 'Mon', 'Tu', 'W', 'Th', 'F', 'Sa' ]);
$calendar->setStartOfWeek('Monday');
echo $calendar->render();Simple Calendar
function __construct($calendarDate = null, $today = null)- \DateTimeInterface | int | string | null
$calendarDate - \DateTimeInterface | false | int | string | null
$today
function setDate($date = null): voidSets the date for the calendar.
- \DateTimeInterface | int | string | null
$date- DateTimeInterface or Date string parsed by strtotime for the calendar date. If null set to current timestamp.
Throws: \Exception
function setCalendarClasses(array $classes): voidSets the class names used in the calendar
[
'calendar' => 'SimpleCalendar',
'leading_day' => 'SCprefix',
'trailing_day' => 'SCsuffix',
'today' => 'today',
'event' => 'event',
'events' => 'events',
] - array{calendar?: string,leading_day?: string,trailing_day?: string,today?: string,event?: string,events?: string}
$classes- Map of element to class names used by the calendar.
function setToday($today = null): voidSets "today"'s date. Defaults to today.
- \DateTimeInterface | false | int | string | null
$today-nullwill default to today,falsewill disable the rendering of Today.
Throws: \Exception
function setWeekDayNames(?array $weekDayNames = null): void- array{0: string,1: string,2: string,3: string,4: string,5: string,6: string} | null
$weekDayNames
function addDailyHtml(string $html, $startDate, $endDate = null): voidAdd a daily event to the calendar
- string
$html- The raw HTML to place on the calendar for this event - \DateTimeInterface | int | string
$startDate- Date string for when the event starts - \DateTimeInterface | int | string | null
$endDate- Date string for when the event ends. Defaults to start date
Throws: \Exception
function clearDailyHtml(): voidClear all daily events for the calendar
function setStartOfWeek($offset): voidSets the first day of the week
- int | string
$offset- Day the week starts on. ex: "Monday" or 0-6 where 0 is Sunday
function show(bool $echo = true): stringReturns/Outputs the Calendar
Use render() method instead.
- bool
$echo- Whether to echo resulting calendar
- string - HTML of the Calendar
function render(): stringReturns the generated Calendar